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
Fix cron timeout #9
Conversation
I did not write a test case for this one as I couldn't reproduce the issue with every second cron expression. If I would write a test with the every minute expression it would slow down the tests significantly 😞 |
71fcaa3
to
0630676
Compare
1 similar comment
src/Bossbat.js
Outdated
timeout = cronTimeout >= 1 ? cronTimeout : 1; | ||
const iterator = parseExpression(definition.cron, { iterator: false }); | ||
const cronTimeout = iterator.next().getTime() - Date.now(); | ||
timeout = cronTimeout > 0 ? cronTimeout : iterator.next().getTime() - Date.now(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of replicating the same iterator code twice, could we just wrap this into a function we can call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Extracted nextCronTimeout
.
This is great, thanks for fixing this bug. I'm curious when the time returned from the iterator would be negative. 0 seems possible although unlikely. |
0630676
to
839679c
Compare
The time returned from the iterator is not be negative, but |
Ah fair, I confirmed that this can happen in my console too: for (var i = 0; i < 10000; i++) console.log(Date.now() - Date.now()) This sometimes prints negative numbers. |
2 similar comments
Published as |
Closes #8.
If
cronTimeout
is0
or negative, the runner has already been invoked. Instead of settingcronTimeout
to1
(one millisecond) we should get the next time from the iterator.