-
Notifications
You must be signed in to change notification settings - Fork 727
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
random times for :hour and :day #596
Conversation
+1 |
@@ -220,6 +221,15 @@ $ whenever | |||
|
|||
This will simply show you your `schedule.rb` file converted to cron syntax. It does not read or write your crontab file. Run `whenever --help` for a complete list of options. | |||
|
|||
### ExceptionNotification | |||
|
|||
If you are using the exception_notification gem (<https://github.com/smartinez87/exception_notification>), enable it for your "runner" cronjobs with: |
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.
Perhaps use a link in Markdown format?
the [exception_notification gem](https://github.com/smartinez87/exception_notification)
def randomize_at(at, time) | ||
return at unless at.nil? | ||
unless time.is_a?(Symbol) && [:hour,:day].include?(time) | ||
#puts 'Sorry, the randomizing-feature works only for symbols :hour and :day' |
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.
Remove debug-oriented code in the PR?
|
||
case time | ||
when :hour then return Random.rand(0...59) | ||
when :day then return [23,0,1,2,3,4,5,6,7].sample.to_s + ':' + Random.rand(0...59).to_s |
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.
Trivial: there are more than double spaces after the symbols?
when :hour then return Random.rand(0...59) | ||
when :day then return [23,0,1,2,3,4,5,6,7].sample.to_s + ':' + Random.rand(0...59).to_s | ||
end | ||
return at |
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.
The case
statement allows an else
case, which would allow all of the "legs" of it to be the last expression of the method = to return the value from the method = to drop the return
keyword.
@@ -60,6 +60,7 @@ class OutputJobsForRolesTest < Whenever::TestCase | |||
file | |||
|
|||
assert_match two_hours + " /bin/bash -l -c 'role1_cmd'", output | |||
assert_match "0 * * * * /bin/bash -l -c 'role2_cmd'", output | |||
#assert_match "0 * * * * /bin/bash -l -c 'role2_cmd'", output |
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.
this is commented out?
This would be really useful functionality. @benlangfeld or @javan is this something you're interested in merging if I clean up the PR? |
I like the idea. If it can be cleaned up, I’ll take a look more closely. |
thanks @benlangfeld. I started working on this over at this branch. I have this patch mostly cleaned up but have found a couple other issues with it. I will check back in with a PR when I either get it sorted or am ready to beg for help. thanks! |
If you use the Symbol-Shortcut (:hour or :day at the moment) and leave the at-argument blank, the exact time of execution will be randomized.
This can reduce the load, when multiple jobs run hourly, for example.