9

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?

VP.
  • 5,122
  • 6
  • 46
  • 71
  • Why not roll the second command into the first one? Seems to me that if they're logically related, you should keep them together. Better yet, make a wrapper task that calls these two and schedule that. – Srdjan Pejic May 08 '11 at 19:17
  • i don't want to couple command "do_this" and rake "do_that". I use command "do_this" for other things. For sure i could create a command "do_something_else" with both, but i just want to know if its possible to do a logican AND between commands with whenever. – VP. May 09 '11 at 10:47
  • Well, firstly, the argument that you want to use one of the rake tasks separately isn't really applicable here, since the two tasks are logically coupled. To answer your second statement, since all whenever does is print out a crontab command and cron doesn't support logical AND, no it's not possible. – Srdjan Pejic May 09 '11 at 11:42

1 Answers1

8

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
Pan Thomakos
  • 34,082
  • 9
  • 88
  • 85