Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scheduling sequential tasks with whenever gem

i'm using whenever to schedule tasks for a rails application.

I have a task like:

every 24.hours do
   command "do_this"
   rake "do_that"
end

my point is, when i write it to my crontab, with whenever -w, i see that it generates two independent tasks running at the same time. the problem is, both are logically a sequence, that means, the rake task, "do_that", should run just if the command "do_this" did already, successfully run.

I tried to contact both like command "do_this" && rake "do_that" but i received a syntax error.

  • Does exist any trick to create this dependence between tasks in whenever?

  • Does the crontab execute the jobs at same time, in parallel or it process N tasks scheduled at the same time in a queue?

like image 291
VP. Avatar asked May 08 '11 16:05

VP.


1 Answers

I think there are two things you could do:

(1) Run the command from the rake task:

task :do_that => :environment do
  system "do_this"
  ...
end

And simplify your schedule.rb file to:

every 24.hours do
   rake "do_that"
end

(2) Run everything from the command line:

every 24.hours do
  command "do_this && rake do_that"
end
like image 197
Pan Thomakos Avatar answered Sep 25 '22 05:09

Pan Thomakos