Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

whenever gem: hourly tasks with minute set

Tags:

cron

whenever

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!

like image 626
Daniel Tsadok Avatar asked Dec 18 '12 06:12

Daniel Tsadok


2 Answers

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
like image 128
mikdiet Avatar answered Nov 16 '22 15:11

mikdiet


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

like image 33
Andrei S Avatar answered Nov 16 '22 14:11

Andrei S