Skip to content

Commit

Permalink
fix(bulkaction): use queuestate to differentiate logic
Browse files Browse the repository at this point in the history
  • Loading branch information
roggervalf committed Mar 7, 2021
1 parent 17bc341 commit 62f72cf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions public/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ $(document).ready(() => {
queueName,
action,
jobs: [],
queueState,
};

$bulkActionContainer.each((index, value) => {
Expand Down
10 changes: 8 additions & 2 deletions src/server/views/api/bulkAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,21 @@ 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)) {
const jobsPromises = jobs.map((id) => queue.getJob(decodeURIComponent(id)));
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);
Expand Down

0 comments on commit 62f72cf

Please sign in to comment.