Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed skipImmediate option in .every #861

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/agenda/every.js
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions lib/job/repeat-every.js
Expand Up @@ -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;
};
16 changes: 16 additions & 0 deletions test/agenda.js
Expand Up @@ -248,6 +248,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() => {
Expand Down