Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Out of sync timing information? #255

Closed
scheung38 opened this issue Oct 13, 2016 · 2 comments
Closed

Out of sync timing information? #255

scheung38 opened this issue Oct 13, 2016 · 2 comments

Comments

@scheung38
Copy link

scheung38 commented Oct 13, 2016

var CronJob = require('cron').CronJob;

// Every 10 second regardless of time
new CronJob('10 * * * * *', function () {
console.log('You will see this message every 10 second');
}, null, true, 'America/Los_Angeles');

But after 3 mins I got
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second

But I was expecting after first minute :
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second

and expecting after second minute :
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second

and expecting after third minute :
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second
You will see this message every 10 second

This test for every 5 seconds

new CronJob('5 * * * * *', function () {
console.log('You will see this message every 5 second');
}, null, true, 'America/Los_Angeles');

You will see this message every 5 second appeared 45 seconds later instead of 5 seconds???

So only this works, for every second

new CronJob('* * * * * *', function () {
console.log('You will see this message every second');
}, null, true, 'America/Los_Angeles');

@fetherolfjd
Copy link

The timing string of 10 * * * * * is saying to run on the tenth second of every minute. To run something every 10 seconds you'd need */10 * * * * *.

@ncb000gt
Copy link
Member

What @fetherolfjd said is true. Also, rather than printing "see this in 10 seconds" you should print new Date().toString() to get a much more accurate picture of when the onTick is firing.

Closing since this is an issue with the syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants