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

Allow for larger values in oneshot timer intervals #784

Merged

Conversation

cwjohnston
Copy link
Contributor

@cwjohnston cwjohnston commented May 15, 2017

In the Sensu project we've added support for scheduling timers using cron syntax. In sensu/sensu#1665 a user reported that they were able to cause an exception in scheduling by configuring a timer that should run on the first of every month.

This pull request seeks to address this exception by using variable types which allow for larger interval values.

@sodabrew
Copy link
Member

Looks good! Could you also add a unit test for a large-future-value timer to tests/test_timers.rb ?

@sodabrew
Copy link
Member

Nudge for a unit test please.

@cwjohnston
Copy link
Contributor Author

I've been AFK for a bit, but I will add a unit test as soon as I am able. 👍

@cwjohnston cwjohnston force-pushed the fix/add_oneshot_timer_interval_type branch from 5f9ba73 to b7fa58b Compare May 24, 2017 18:10
@cwjohnston
Copy link
Contributor Author

@sodabrew ready for your review

@sodabrew
Copy link
Member

Looks good! One last thought: in lib/eventmachine.rb, the value is converted to float before it is multiplied by 1000: (interval.to_f * 1000).to_i I wonder if this was needed in some ancient version of Ruby that did not automatically upgrade to big ints. At least since Ruby 1.8.7 a Fixnum will transparently upgrade to a Bignum if needed. So I think the code can be changed to internal.to_i * 1000 or even interval * 1000 (at the risk of introducing a subtle API change that a numeric-like string would no longer be a valid argument).

Since Ruby 1.8.7 a Fixnum will transparently upgrade to a Bignum if
needed. As such we should no longer need to cast to float before
multiplying by 1000 for converting seconds to miliseconds.
@cwjohnston
Copy link
Contributor Author

@sodabrew I've attempted the change you suggested but it seems to have broken a number of tests for reasons unclear to me. Can you see a reason for the breakage? Should I revert this latest commit?

@sodabrew
Copy link
Member

I was wrong about the placement of the .to_i, it causes a float argument to be rounded down to 0. Either the existing code, or just interval * 1000, but now that I realize the reason for the cast let's leave it. Sorry! I'll merge immediately after you pull the last commit off.

@sodabrew sodabrew merged commit 7bc6076 into eventmachine:master Jun 12, 2017
@sodabrew
Copy link
Member

Thank you! Glad to get this landed now.

@sodabrew
Copy link
Member

Released today with Eventmachine 1.2.5 on Rubygems!

@cwjohnston cwjohnston deleted the fix/add_oneshot_timer_interval_type branch July 28, 2017 13:33
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.

2 participants