cfurst/CronJobManager

function not execute in Add Task

Closed this issue · 17 comments

In Add task function part is not execute.

manager.add('next_job', '0 40 * * * *', function () { 
 console.log('------------------------ tick...'); 
});  

console.log is not print out in console.

interesting. I think you may need to add the other options included. like a boolean to start right away, an end function and a timezone..
However, I'll look into this.

yes. sometime its working and sometime its not working. Any idea?

I have not been able to reproduce as yet.. I'll take a look.

Fine.

 manager.add('next_job', '0 40 * * * *', function() { 
   console.log('schedule run');                                                                                                          
 });        
 manager.start(schedule_value);                   

Here, If I will update or Add new schedule it's not execute on next minute. I have to restart my server to been able to run this schedule.

If I will update time to

manager.update('next_job', '0 41 * * * *', function() {
console.log('update schedule run');                                  
}); 

In this update case, its not print console.log unless I restart my server as I said.

console.log("No of Jobs running : " + manager.listCrons());

Its shows that job is actually running but not execute.

I'm wondering if it's updating to run on the 41st minute of the Next hour.. Also, just to make sure I get this straight, you are setting your cron to run on the 40th minute of every hour, then change it to run on the 41st minute of ever hour. 40th mintue comes and there's no log and the 41st minute comes and there's no log.

Does that sound right? Also I notice you set the seconds field to 0 are you sure that you are setting the next minute before the clock hits 41 minutes and 0 seconds? I don't think this library supports the '?' parameter as other crontab libs do.

ah wait.. I see your problem..You're missing a '. I think you should be doing this:

manager.update('next_job', '0 41 * * * *', function() {
console.log('update schedule run');                                  
}); 

try that with a terminating ' after your tab expression

' I forgot to add here, otherwise in my code cron time is completely different. I have a pattern like '0 00 11 * * 0-6' which execute every day at 11:00 AM.

But my issue is when the time comes to execute it sometimes it will execute and sometimes it will not. I have added console in the execution for testing but its work like 3/5 times. Any idea?

What version of nodejs are you running ? I have not been able to reproduce this thus far.

Node : v4.8.6

It happened again. I added schedule on 7:45 PM and it was not executed.
Then I updated to 7:48PM and again it was not executed.
What can be an issue ???

Moreover, when I do console...
console.log("No of Jobs running : " + manager.listCrons());
It's shows status: Running but I don't know for what reason its not executing in real time!

What timezone is the machine running on? Do you have a TZ environment variable set? What is the system time when you are setting the schedule? It sounds to me like you are looking at your one source of time while your machine has a totally different time. I'm running a test now..

system TZ : Asia/Kolkata
And In manager.add -- Mentioned timezone is also Asia/Kolkata.

Do find an issue like for Example, if you set up schedule at 11:00AM and it wouldn't execute.

I'm still testing, so far all tests are not reproducing your issue.

Here is output from a crontab running for over 12 hours:

we have crons: {
'first_key': 0 30 * * * *: () => {console.log("[" + new Date() + "] =====> 30 minutes past the hour: " + new Date().getHours())}: Running
}
[Tue Feb 13 2018 09:30:01 GMT+0530 (IST)] =====> 30 minutes past the hour: 9
[Tue Feb 13 2018 10:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 10
[Tue Feb 13 2018 11:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 11
[Tue Feb 13 2018 12:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 12
[Tue Feb 13 2018 13:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 13
[Tue Feb 13 2018 14:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 14
[Tue Feb 13 2018 15:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 15
[Tue Feb 13 2018 16:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 16
[Tue Feb 13 2018 17:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 17
[Tue Feb 13 2018 18:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 18
[Tue Feb 13 2018 19:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 19
[Tue Feb 13 2018 20:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 20
[Tue Feb 13 2018 21:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 21
[Tue Feb 13 2018 22:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 22
[Tue Feb 13 2018 23:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 23
[Wed Feb 14 2018 00:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 0
[Wed Feb 14 2018 01:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 1
[Wed Feb 14 2018 02:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 2
[Wed Feb 14 2018 03:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 3
[Wed Feb 14 2018 04:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 4
[Wed Feb 14 2018 05:30:01 GMT+0530 (IST)] =====> 30 minutes past the hour: 5
[Wed Feb 14 2018 06:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 6
[Wed Feb 14 2018 07:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 7
[Wed Feb 14 2018 08:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 8
[Wed Feb 14 2018 09:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 9
[Wed Feb 14 2018 10:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 10
[Wed Feb 14 2018 11:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 11
[Wed Feb 14 2018 12:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 12
[Wed Feb 14 2018 13:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 13
[Wed Feb 14 2018 14:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 14
[Wed Feb 14 2018 15:30:01 GMT+0530 (IST)] =====> 30 minutes past the hour: 15
[Wed Feb 14 2018 16:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 16
[Wed Feb 14 2018 17:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 17
[Wed Feb 14 2018 18:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 18
[Wed Feb 14 2018 19:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 19
[Wed Feb 14 2018 20:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 20
[Wed Feb 14 2018 21:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 21
[Wed Feb 14 2018 22:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 22
[Wed Feb 14 2018 23:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 23
[Thu Feb 15 2018 00:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 0
[Thu Feb 15 2018 01:30:00 GMT+0530 (IST)] =====> 30 minutes past the hour: 1

So I cannot reproduce your issue. it is probably somewhere else in your code.

I can see in your example, you are right. But when you update / change your schedule from 30 min to every 35 min then you might get that issue for sure.

I would say Update your schedule in between and it will stop executing your schedule. I am facing same issue again and again.

so this is happening when you make the interval longer? can you show me code where you are updating this on the fly?

also you have to keep in mind this is running off of the nodejs scheduler as well as your system time.. so if you have a lot of other functions scheduled around the same time as an update, it may not be exact. Maybe if you put the update in a process.nextTick() call, it might behave more like you expect?