scheduling sequential tasks with whenever gem
Asked Answered
B

1

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?

Burma answered 8/5, 2011 at 16:24 Comment(3)
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.Princedom
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.Burma
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.Princedom
P
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
Pebbly answered 9/5, 2011 at 20:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.