whenever gem and scheduling a job every n min starting at an offset
It sounds like you have a dependency between the two jobs, so there are two ways I think you can handle this. If you want to run at 1,6,11,16 and so on, as your question suggests, then simply use raw cron syntax:
every '0,5,10,15,20,25,30,35,40,45,50,55 * * * *' do command "echo 'you can use raw cron syntax one'"endevery '1,6,11,16,21,26,31,36,41,46,51,56 * * * *' do command "echo 'you can use raw cron syntax two'"end
But it's probably better to execute the second job once the first one is done. This should ensure that the jobs don't overlap and that the second only runs when after the first completes.
every 5.minutes do command "echo 'one' && echo 'two'"end
every
expects an integer.
To avoid thundering herd problem, you can do this.
every 5.minutes - 10.seconds do command "echo first task"endevery 5.minutes + 10.seconds do command "echo second task"end
You can randomise the offset too
def some_seconds (-10..10).to_a.sample.secondsendevery 5.minutes + some_seconds do command "echo first task"endevery 5.minutes + some_seconds do command "echo second task"end
Like other answers this won't work for tasks depending on each other. If your tasks depend on each other, you should use rake
to handle it for you or run next one manually in your task.
# shedule.rbevery 5.minutes do rake 'jobs:last_one'end# Rakefile.rbnamespace :jobs do task :first_one do sh 'first command' end task second_one: [:first_one] do sh 'second_command that_should_run_after_first_one' end task last_one: [:second_one] do sh 'last_command that_should_run_after_all_commands' endend
Yes, that should be valid. Look at https://github.com/javan/whenever/blob/master/lib/whenever/cron.rb
Look at the parse_time method. These lines in particular:
when 1.hour...1.day hour_frequency = (@time / 60 / 60).round timing[0] = @at.is_a?(Time) ? @at.min : @at timing[1] = comma_separated_timing(hour_frequency, 23)