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

Fix cron timeout #9

Merged
merged 2 commits into from Feb 27, 2017
Merged

Fix cron timeout #9

merged 2 commits into from Feb 27, 2017

Conversation

tjokimie
Copy link
Contributor

@tjokimie tjokimie commented Feb 26, 2017

Closes #8.

If cronTimeout is 0 or negative, the runner has already been invoked. Instead of setting cronTimeout to 1 (one millisecond) we should get the next time from the iterator.

@tjokimie
Copy link
Contributor Author

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 😞

@coveralls
Copy link

coveralls commented Feb 26, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling 0630676 on tjokimie:fix-cron-timeout into 022a786 on airbnb:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 0630676 on tjokimie:fix-cron-timeout into 022a786 on airbnb:master.

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();
Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Extracted nextCronTimeout.

@kesne
Copy link
Collaborator

kesne commented Feb 27, 2017

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.

@tjokimie
Copy link
Contributor Author

The time returned from the iterator is not be negative, but cronTimeout (the result of iterator.next().getTime() - Date.now()) can be negative as iterator.next().getTime() can return current time and after that Date.now() will be subtracted from it.

@kesne
Copy link
Collaborator

kesne commented Feb 27, 2017

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.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 839679c on tjokimie:fix-cron-timeout into decbf21 on airbnb:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 839679c on tjokimie:fix-cron-timeout into decbf21 on airbnb:master.

@coveralls
Copy link

coveralls commented Feb 27, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling 839679c on tjokimie:fix-cron-timeout into decbf21 on airbnb:master.

@kesne kesne merged commit 5ac3b21 into airbnb:master Feb 27, 2017
@kesne
Copy link
Collaborator

kesne commented Feb 27, 2017

Published as bossbat@1.1.1. Thank you so much for finding this and contributing!

@tjokimie tjokimie deleted the fix-cron-timeout branch February 27, 2017 20:32
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

Successfully merging this pull request may close these issues.

None yet

3 participants