cron job with date never stops #34

Closed
jgallen23 opened this Issue May 8, 2012 · 2 comments

2 participants

@jgallen23

This code will wait 3 seconds and then print "run" every second

var d = new Date().getTime() + 3000;                                                                                                                                                                                                                                      
var job = cron.job(new Date(d), function() {                                                                                                                                                                                                                              
  console.log('run');                                                                                                                                                                                                                                                     
});                                                                                                                                                                                                                                                                       
job.start();

Issue appears to be here:

//add 1 second so next time isn't now (can cause timeout to be 0)                                                                                                                                                                                                   
date.setSeconds(date.getSeconds() + 1);          

If I remove this line, it fixes it. What was the use case where you would need to add a second?

@jgallen23

When I removed that line, cron jobs don't fire correctly. So I'm currently doing this:

    if (this.realDate) {
      return date;
    } else {
      //add 1 second so next time isn't now (can cause timeout to be 0)
      date.setSeconds(date.getSeconds() + 1);
    }
@ncb000gt ncb000gt added a commit that referenced this issue May 9, 2012
@ncb000gt Make sure date values only fire once per GH-34.
Signed-off-by: Nick Campbell <nicholas.j.campbell@gmail.com>
b9b29fe
@ncb000gt
Owner

Let me know if you notice it not working again. The quick fix I put in should solve the issues.

@ncb000gt ncb000gt closed this May 9, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment