Skip to content

Commit

Permalink
fix: Do not reenqueue disabled and archived jobs (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pranav Ravichandran authored May 4, 2018
1 parent 74d47b5 commit 334eb92
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class ExecutorQueue extends Executor {
.catch(() => Promise.resolve());
}

if (buildCron) {
if (buildCron && config.job.state === 'ENABLED' && !config.job.archived) {
await this.connect();

const next = cron.next(cron.transform(buildCron, config.job.id));
Expand Down
30 changes: 30 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,36 @@ describe('index test', () => {
assert.calledWith(redisMock.hdel, 'periodicBuildConfigs', testJob.id);
});
});

it('stops but does not reEnqueue an existing job if it is disabled', () => {
testDelayedConfig.isUpdate = true;
testDelayedConfig.job.state = 'DISABLED';
testDelayedConfig.job.archived = false;
executor.startPeriodic(testDelayedConfig).then(() => {
assert.calledOnce(queueMock.connect);
assert.notCalled(redisMock.hset);
assert.notCalled(queueMock.enqueueAt);
assert.calledWith(queueMock.delDelayed, 'periodicBuilds', 'startDelayed', [{
jobId: testJob.id
}]);
assert.calledWith(redisMock.hdel, 'periodicBuildConfigs', testJob.id);
});
});

it('stops but does not reEnqueue an existing job if it is archived', () => {
testDelayedConfig.isUpdate = true;
testDelayedConfig.job.state = 'ENABLED';
testDelayedConfig.job.archived = true;
executor.startPeriodic(testDelayedConfig).then(() => {
assert.calledOnce(queueMock.connect);
assert.notCalled(redisMock.hset);
assert.notCalled(queueMock.enqueueAt);
assert.calledWith(queueMock.delDelayed, 'periodicBuilds', 'startDelayed', [{
jobId: testJob.id
}]);
assert.calledWith(redisMock.hdel, 'periodicBuildConfigs', testJob.id);
});
});
});

describe('_start', () => {
Expand Down

0 comments on commit 334eb92

Please sign in to comment.