I'm using node-schedule npm package to schedule the job. I referred below link to set the job name/id for different jobs, Cancel node-schedule event after it has been set
It works well when I directly use the cron expression to schedule the job. But it is not working when I used RecurrenceRule() to schedule the job.
Please help me to solve this problem.
Working code snippet for, scheduling job with job id and cron expression,
// code that works
function test(fn)
{
let rule = '* * * * *'
let jobId = "my_event_1"
schedule.scheduleJob(jobId,rule,()=>{fn()})
}
test(print)
print function,
function print()
{
console.log("HELLO",new Date())
}
Code that doesn't work with recurrence rule,
// Recurrence rule used
function my_scheduleJob(id,tz,cron_expression,function_name)
{
var mxTimezones = "Asia/Kolkata";
var interval = parser.parseExpression(cron_expression, options);
var cronDate = interval.next();
var rule = new schedule.RecurrenceRule();
rule.second = cronDate.getSeconds();
rule.minute = cronDate.getMinutes();
rule.tz = mxTimezones; // You can specify a timezone!
schedule.scheduleJob(rule,()=>{
console.log("Scheduler test-------")
function_name(rule.tz)
})
}
my_scheduleJob("job1", "Asia/Kolkata", "* * * * *", print)
The reason I used recurrence rule is to set the timezone. Is it possible to use recurrence rule and job id to schedule the job?
Thanks in advance !!!