From afb55f9b41aca8aea675ebbcaf7133fb119b3c3f Mon Sep 17 00:00:00 2001 From: roggervalf Date: Sat, 27 Apr 2024 13:09:19 -0500 Subject: [PATCH 1/4] feat(job): update data --- docker-compose.yml | 7 ++++ example/bull.js | 2 +- package.json | 2 ++ public/dashboard.js | 32 ++++++++++++++++++ src/server/app.js | 1 + src/server/views/api/index.js | 2 ++ src/server/views/api/jobDataUpdate.js | 25 ++++++++++++++ .../views/dashboard/templates/jobDetails.hbs | 7 +++- .../views/partials/dashboard/jobDetails.hbs | 33 ++++++++++++++++++- 9 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 docker-compose.yml create mode 100644 src/server/views/api/jobDataUpdate.js diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..de1b7db6 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,7 @@ +version: '3.2' +services: + redis: + image: redis:6-alpine + container_name: redis-6 + ports: + - 6379:6379 diff --git a/example/bull.js b/example/bull.js index a4146e22..62acf9c2 100644 --- a/example/bull.js +++ b/example/bull.js @@ -39,7 +39,7 @@ async function main() { } }); - await queue.add({}); + await queue.add({data: 'data'}); // adding delayed jobs const delayedJob = await queue.add({}, {delay: 60 * 1000}); diff --git a/package.json b/package.json index 9bc5c382..09972819 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,8 @@ "ci": "npm run lint && if [ -z \"$CI\" ]; then npm run ci:commitlint; fi", "ci:commitlint": "commitlint --from \"origin/${GITHUB_BASE_REF:-master}\"", "cm": "git cz", + "dc:up": "docker-compose -f docker-compose.yml up -d", + "dc:down": "docker-compose -f docker-compose.yml down", "dry:run": "npm publish --dry-run", "lint": "prettier -c .", "lint:staged": "lint-staged", diff --git a/public/dashboard.js b/public/dashboard.js index 6375c9f2..268abb5c 100644 --- a/public/dashboard.js +++ b/public/dashboard.js @@ -314,6 +314,38 @@ $(document).ready(() => { }); }); + $('.js-update-job-data').on('click', function (e) { + e.preventDefault(); + const jobId = $(this).data('job-id'); + const queueName = $(this).data('queue-name'); + const queueHost = $(this).data('queue-host'); + const stringifiedData = JSON.stringify(window.jsonEditor.get()); + const r = window.confirm( + `Update job #${jobId} data in queue "${queueHost}/${queueName}"?` + ); + + if (r) { + $.ajax({ + url: `${basePath}/api/queue/${encodeURIComponent( + queueHost + )}/${encodeURIComponent(queueName)}/job/${encodeURIComponent( + jobId + )}/data`, + type: 'PUT', + data: stringifiedData, + contentType: 'application/json', + }) + .done(() => { + alert('Job data successfully updated!'); + window.location.reload(); + }) + .fail((jqXHR) => { + window.alert('Failed to update job data, check console for error.'); + console.error(jqXHR.responseText); + }); + } + }); + $('.js-add-flow').on('click', function () { const data = window.jsonEditor.get(); const flow = JSON.stringify({data}); diff --git a/src/server/app.js b/src/server/app.js index a8a5dd61..e7ac58e9 100644 --- a/src/server/app.js +++ b/src/server/app.js @@ -27,6 +27,7 @@ module.exports = function (config) { app.locals.vendorPath = '/vendor'; app.locals.customCssPath = config.customCssPath; app.locals.customJsPath = config.customJsPath; + app.locals.version = '4.2.0'; app.set('views', `${__dirname}/views`); app.set('view engine', 'hbs'); diff --git a/src/server/views/api/index.js b/src/server/views/api/index.js index 50523e44..12b53987 100644 --- a/src/server/views/api/index.js +++ b/src/server/views/api/index.js @@ -6,6 +6,7 @@ const jobAdd = require('./jobAdd'); const jobPromote = require('./jobPromote'); const jobRetry = require('./jobRetry'); const jobRemove = require('./jobRemove'); +const jobDataUpdate = require('./jobDataUpdate'); const repeatableJobRemove = require('./repeatableJobRemove'); const bulkJobsPromote = require('./bulkJobsPromote'); const bulkJobsRemove = require('./bulkJobsRemove'); @@ -24,6 +25,7 @@ router.delete( '/queue/:queueHost/:queueName/repeatable/job/:id', repeatableJobRemove ); +router.put('/queue/:queueHost/:queueName/job/:id/data', jobDataUpdate); router.patch('/queue/:queueHost/:queueName/job/:id', jobRetry); router.put('/queue/:queueHost/:queueName/pause', queuePause); router.put('/queue/:queueHost/:queueName/resume', queueResume); diff --git a/src/server/views/api/jobDataUpdate.js b/src/server/views/api/jobDataUpdate.js new file mode 100644 index 00000000..e9cdb5ea --- /dev/null +++ b/src/server/views/api/jobDataUpdate.js @@ -0,0 +1,25 @@ +async function handler(req, res) { + const {queueName, queueHost, id} = req.params; + const data = req.body; + + const {Queues} = req.app.locals; + + const queue = await Queues.get(queueName, queueHost); + if (!queue) return res.status(404).json({error: 'queue not found'}); + + const job = await queue.getJob(id); + if (!job) return res.status(404).send({error: 'job not found'}); + + try { + if (job.updateData) { + await job.updateData(data); + } else { + await job.update(data); + } + } catch (err) { + return res.status(500).json({error: err.message}); + } + return res.sendStatus(200); +} + +module.exports = handler; diff --git a/src/server/views/dashboard/templates/jobDetails.hbs b/src/server/views/dashboard/templates/jobDetails.hbs index 8b06853b..7b2f43e4 100644 --- a/src/server/views/dashboard/templates/jobDetails.hbs +++ b/src/server/views/dashboard/templates/jobDetails.hbs @@ -1,6 +1,6 @@

Queue {{ queueHost }}/{{ queueName }}

-{{> dashboard/jobDetails job basePath=basePath queueName=queueName queueHost=queueHost jobState=jobState stacktraces=stacktraces}} +{{> dashboard/jobDetails job basePath=basePath queueName=queueName queueHost=queueHost jobState=jobState stacktraces=stacktraces view=true}} {{#contentFor 'sidebar'}}
  • Queues Overview
  • @@ -12,4 +12,9 @@ {{#if hasFlows}}
  • Flows Overview
  • {{/if}} +{{/contentFor}} + +{{#contentFor 'script'}} +window.jsonEditor = new JSONEditor(document.getElementById('jsoneditor'), { modes: ['code','tree','text'] }); +window.jsonEditor.set({{json job.data true}}) {{/contentFor}} \ No newline at end of file diff --git a/src/server/views/partials/dashboard/jobDetails.hbs b/src/server/views/partials/dashboard/jobDetails.hbs index c31f9528..ceffac50 100644 --- a/src/server/views/partials/dashboard/jobDetails.hbs +++ b/src/server/views/partials/dashboard/jobDetails.hbs @@ -75,8 +75,10 @@
    Permalinks
    + {{#unless view}} Job {{ this.id }} + {{/unless}} JSON
    @@ -133,7 +135,36 @@
    Data
    -
    {{json this.data true}}
    + +{{#unless queue.IS_BEE}} +{{#if view }} +
    + +
    +
    +
    +{{/if}} +{{/unless}} +
    {{json this.data true}}
    +{{#unless queue.IS_BEE}} +{{#if view }} +
    +
    +
    +
    +
    +
    Update
    +
    +
    +
    +
    +
    +{{/if}} +{{/unless}} {{#if this.queue.IS_BULLMQ}} {{#if this.parent }} From f23cbf2e8cb91b43e51208dd05e200a64112a65b Mon Sep 17 00:00:00 2001 From: roggervalf Date: Sat, 27 Apr 2024 13:21:43 -0500 Subject: [PATCH 2/4] chore: check if editor is present --- src/server/views/dashboard/templates/jobDetails.hbs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/server/views/dashboard/templates/jobDetails.hbs b/src/server/views/dashboard/templates/jobDetails.hbs index 7b2f43e4..781a51ab 100644 --- a/src/server/views/dashboard/templates/jobDetails.hbs +++ b/src/server/views/dashboard/templates/jobDetails.hbs @@ -15,6 +15,8 @@ {{/contentFor}} {{#contentFor 'script'}} -window.jsonEditor = new JSONEditor(document.getElementById('jsoneditor'), { modes: ['code','tree','text'] }); -window.jsonEditor.set({{json job.data true}}) +if(document.getElementById('jsoneditor')) { + window.jsonEditor = new JSONEditor(document.getElementById('jsoneditor'), { modes: ['code','tree','text'] }); + window.jsonEditor.set({{json job.data true}}) +} {{/contentFor}} \ No newline at end of file From 2fcbe0f4395d4b6ff911907542725fe503889b0b Mon Sep 17 00:00:00 2001 From: roggervalf Date: Sat, 27 Apr 2024 13:22:25 -0500 Subject: [PATCH 3/4] chore: update version --- src/server/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/app.js b/src/server/app.js index e7ac58e9..cacc5545 100644 --- a/src/server/app.js +++ b/src/server/app.js @@ -27,7 +27,7 @@ module.exports = function (config) { app.locals.vendorPath = '/vendor'; app.locals.customCssPath = config.customCssPath; app.locals.customJsPath = config.customJsPath; - app.locals.version = '4.2.0'; + app.locals.version = '4.3.0'; app.set('views', `${__dirname}/views`); app.set('view engine', 'hbs'); From 1a4a8e9c27fddf58fc1a3730eef129880b59cbf8 Mon Sep 17 00:00:00 2001 From: roggervalf Date: Sat, 27 Apr 2024 13:32:37 -0500 Subject: [PATCH 4/4] chore: remove version --- example/bee.js | 2 +- src/server/app.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/example/bee.js b/example/bee.js index 7f804726..fa62cc6d 100644 --- a/example/bee.js +++ b/example/bee.js @@ -30,7 +30,7 @@ async function main() { .delayUntil(Date.now() + 60 * 1000) .save(); - const job = await queue.createJob({}).save(); + await queue.createJob({}).save(); Arena( { diff --git a/src/server/app.js b/src/server/app.js index cacc5545..a8a5dd61 100644 --- a/src/server/app.js +++ b/src/server/app.js @@ -27,7 +27,6 @@ module.exports = function (config) { app.locals.vendorPath = '/vendor'; app.locals.customCssPath = config.customCssPath; app.locals.customJsPath = config.customJsPath; - app.locals.version = '4.3.0'; app.set('views', `${__dirname}/views`); app.set('view engine', 'hbs');