Skip to content
Permalink
Browse files

Fixed skipImmediate option in .every (#861)

  • Loading branch information
erics2783 authored and simison committed Nov 24, 2019
1 parent ffd5416 commit 57c96da703316854e1d4115c4f87e9cb887ffc72
Showing with 18 additions and 1 deletion.
  1. +0 −1 lib/agenda/every.js
  2. +2 −0 lib/job/repeat-every.js
  3. +16 −0 test/agenda.js
@@ -25,7 +25,6 @@ module.exports = async function(interval, names, data, options) {

job.attrs.type = 'single';
job.repeatEvery(interval, options);
job.computeNextRunAt();
await job.save();

return job;
@@ -16,6 +16,8 @@ module.exports = function(interval, options) {
this.attrs.lastRunAt = new Date();
this.computeNextRunAt();
this.attrs.lastRunAt = undefined;
} else {
this.computeNextRunAt();
}

return this;
@@ -253,6 +253,22 @@ describe('Agenda', () => {
const res = await jobs.jobs({name: 'shouldBeSingleJob'});
expect(res).to.have.length(1);
});
it('should not run immediately if options.skipImmediate is true', async() => {
const jobName = 'send email';
await jobs.every('5 minutes', jobName, {}, {skipImmediate: true});
const job = (await jobs.jobs({name: jobName}))[0];
const nextRunAt = job.attrs.nextRunAt.getTime();
const now = new Date().getTime();
expect((nextRunAt - now) > 0).to.equal(true);
});
it('should run immediately if options.skipImmediate is false', async() => {
const jobName = 'send email';
await jobs.every('5 minutes', jobName, {}, {skipImmediate: false});
const job = (await jobs.jobs({name: jobName}))[0];
const nextRunAt = job.attrs.nextRunAt.getTime();
const now = new Date().getTime();
expect((nextRunAt - now) <= 0).to.equal(true);
});
});
describe('with array of names specified', () => {
it('returns array of jobs', async() => {

0 comments on commit 57c96da

Please sign in to comment.
You can’t perform that action at this time.