From 62f72cf14d5a5ef68e59bbdbf1f2ba2e70763f23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?rogger=20andr=C3=A9=20valverde=20flores?= Date: Sun, 7 Mar 2021 12:32:00 -0500 Subject: [PATCH] fix(bulkaction): use queuestate to differentiate logic --- public/dashboard.js | 1 + src/server/views/api/bulkAction.js | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/public/dashboard.js b/public/dashboard.js index 03596c7c..c5ff93da 100644 --- a/public/dashboard.js +++ b/public/dashboard.js @@ -110,6 +110,7 @@ $(document).ready(() => { queueName, action, jobs: [], + queueState, }; $bulkActionContainer.each((index, value) => { diff --git a/src/server/views/api/bulkAction.js b/src/server/views/api/bulkAction.js index 1b3fdc1a..5c0d27b9 100644 --- a/src/server/views/api/bulkAction.js +++ b/src/server/views/api/bulkAction.js @@ -16,7 +16,7 @@ function bulkAction(action) { const queue = await Queues.get(queueName, queueHost); if (!queue) return res.status(404).send({ error: 'queue not found' }); - const { jobs } = req.body; + const { jobs, queueState } = req.body; try { if (!_.isEmpty(jobs)) { @@ -24,7 +24,13 @@ function bulkAction(action) { const fetchedJobs = await Promise.all(jobsPromises); const actionPromises = action === 'retry' - ? fetchedJobs.map((job) => Queues.set(queue, job.data, job.name)) + ? fetchedJobs.map((job) => { + if (queueState === 'failed' && typeof job.retry === 'function') { + return job.retry(); + } else { + return Queues.set(queue, job.data, job.name); + } + }) : fetchedJobs.map((job) => job[action]()); await Promise.all(actionPromises); return res.sendStatus(200);