Agenda: [QUESTION] How to save job but not execute job now !

Created on 21 Mar 2018  路  4Comments  路  Source: agenda/agenda

I define my job be:

function dieukhien(paramcontrol) {
request.post({url: config.targetpath, form: paramcontrol}, function (err, httpResponse, body) {
console.log('pushed')
});
}

agenda.define(JobControl._id + '-' + JobControl.type, function (job) {
dieukhien('test data');
});
var scheduleaagenda = agenda.create(JobControl._id + '-' + JobControl.type);
let timeset = "" + JobControl.scheduletime.second + " " + JobControl.scheduletime.minute + " " + JobControl.scheduletime.hour + " * * " + JobControl.scheduletime.dayofweek;
scheduleaagenda.repeatEvery(timeset);
scheduleaagenda.save();
agenda.start();

.
after define , i save job by ----- scheduleaagenda.save();
but save() function will execute dieukhien() . that is bad ! , how can i save this job and not execute dieukhien() ??
Please help me.

support

Most helpful comment

You can combine repeatEvery() and schedule() to achieve what you want.

By default, agenda sets any new job's scheduled run time to now. Adding the repeatEvery will make future runs follow the schedule specified, but not the first one. To get the behavior you want, you can compute the next date to run from the cron schedule you're using in repeatEvery and call .schedule(date) before saving.

Hope that helps!

All 4 comments

+1

You can combine repeatEvery() and schedule() to achieve what you want.

By default, agenda sets any new job's scheduled run time to now. Adding the repeatEvery will make future runs follow the schedule specified, but not the first one. To get the behavior you want, you can compute the next date to run from the cron schedule you're using in repeatEvery and call .schedule(date) before saving.

Hope that helps!

if you're wondering how to get the next date from your cron schedule, you can check out how agenda does it internally for subsequent runs here: https://github.com/agenda/agenda/blob/master/lib/job/compute-next-run-at.js#L35-L36

Wow .@princjef Thank you so much . :D . I will try it now .

Was this page helpful?
0 / 5 - 0 ratings