Agenda: Job runs immediately when the app starts

Created on 18 Jul 2016  路  5Comments  路  Source: agenda/agenda

I'm scheduling a job using this code:

var job = global.agenda.create('send happy hour notification', {});
job.repeatEvery('0 21 * * *');
job.unique({});
job.save();

So the job should run everyday at 21:00.
But every time I run my app it runs this job..
Am I doing something wrong?

Most helpful comment

@jakeorr Thanks! Seems like it works..

All 5 comments

If you run a job.computeNextRunAt(); after setting the repeat interval, it should set the next run time correctly.

@jakeorr Thanks! Seems like it works..

@jakeorr Shouldn't this be the default or at least an option when creating a job?

@bvallelunga I didn't write this code so I'm not sure what the thinking was. It may have been intentional to always have the job run immediately on creation. If you have a better way to do it, you could submit a PR.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adamhalasz picture adamhalasz  路  3Comments

surazzarus picture surazzarus  路  3Comments

mKontakis picture mKontakis  路  3Comments

weeco picture weeco  路  4Comments

michelem09 picture michelem09  路  6Comments