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.
+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 .
Most helpful comment
You can combine
repeatEvery()andschedule()to achieve what you want.By default, agenda sets any new job's scheduled run time to now. Adding the
repeatEverywill 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 inrepeatEveryand call.schedule(date)before saving.Hope that helps!