Skip to content

Commit

Permalink
Merge pull request #59 from screwdriver-cd/bugfix
Browse files Browse the repository at this point in the history
fix: filter out non-periodic jobs when doing duplicate check
  • Loading branch information
minzcmu authored May 15, 2019
2 parents b0adac4 + 167a9e7 commit 4f192f3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
15 changes: 15 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 4f192f3

Please sign in to comment.