whenever gem: hourly tasks with minute set
Asked Answered
N

2

8

I have a bunch of cronjobs managed by whenever. Everything works fine, but I have a few hourly cronjobs that are all triggered at the same time, so I'd like to stagger them. Worst case scenario I'm able to update the crontab manually, but I'd really rather take of this in schedule.rb.

TL;DR - I would like to do something like:

every 1.hour, at: ":00" do #task 1
every 1.hour, at: ":10" do #task 2
every 1.hour, at: ":20" do #task 3

Thanks!

Nynorsk answered 18/12, 2012 at 6:17 Comment(0)
B
30

This can be done this way:

every :hour, at: 0 do #task 1
every :hour, at: 10 do #task 2
every :hour, at: 20 do #task 3
Bobbie answered 30/9, 2013 at 16:51 Comment(1)
Note, this does not work: every :hour, at: 10.minutesDepute
E
1

I'm using this for your case:

every '5 * * * *' do
  #do stuff here
end

This will launch at the 5 minute mark (every hour, every day, every month, every day of the week)

For other cases like this where whenever might not have a built in helper, check out this link

Epicurean answered 21/1, 2013 at 10:7 Comment(1)
This seems to be an obvious feature. Is there any obstacle to contributing this to the gem yet, or is it just that nobody's gotten around to it yet?Bole

© 2022 - 2024 — McMap. All rights reserved.