From 167a9e7698aed026b121fd3bfa2cb1670cf33fa6 Mon Sep 17 00:00:00 2001 From: Min Zhang Date: Wed, 15 May 2019 15:32:00 -0700 Subject: [PATCH] fix: filter out non-periodic jobs when doing duplicate check --- index.js | 5 +++-- test/index.test.js | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index e065d68..c6e25ca 100644 --- a/index.js +++ b/index.js @@ -322,9 +322,10 @@ class ExecutorQueue extends Executor { // example job: "{\"class\":\"startDelayed\",\"queue\":\"periodicBuilds\",\"args\":[{\"jobId\":212502}]}" if (jobs && jobs.length > 0) { - const parsedJobs = jobs.maps(j => JSON.parse(j)); + const parsedJobs = jobs.map(j => JSON.parse(j)); - if (parsedJobs.find(j => j.args[0].jobId === job.id)) { + if (parsedJobs.find(j => j.class === 'startDelayed' + && j.args[0].jobId === job.id)) { return Promise.resolve(); } } diff --git a/test/index.test.js b/test/index.test.js index 9e54bff..9e46372 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -256,6 +256,21 @@ describe('index test', () => { }]); })); + it('do not enqueue the same delayed job in the queue', () => { + const job = { + class: 'startDelayed', + queue: 'periodicBuilds', + args: [{ jobId: testJob.id }] + }; + + redisMock.lrange = sinon.stub().yieldsAsync(null, [JSON.stringify(job)]); + + return executor.startPeriodic(testDelayedConfig).then(() => { + assert.calledWith(cronMock.next, 'H H H H H'); + assert.notCalled(queueMock.enqueueAt); + }); + }); + it('stops and reEnqueues an existing job if isUpdate flag is passed', () => { testDelayedConfig.isUpdate = true;