javan/whenever

How to execute multiple tasks with a single runner ?

mbautista opened this issue · 1 comments

Hello,
We use Whenever on a large project with lots of scheduled tasks on different hours. For example at 9am :

every :day, at: '09:00am' do
  runner 'MyClass1.task1'
  runner 'MyClass2.task2'
  ...
  runner 'MyClass10.task10'
end

The problem is that this creates 10 cron tasks at 9am, and lots of processes are spawned simultaneously and uses a lot of RAM.
So instead we would like to run a single cron task with 10 chained tasks.

I thought we could use the following syntax (untested) :

every :day, at: '09:00am' do
  runner 'MyClass1.task1; MyClass2.task2'; ...; MyClass10.task10'
end

But this would make long lines and the code would hardly be readable.

We could also create a Ruby class, say "SchedulerTask" and create a static method , say "SchedulerTask.9am", and then use it the scheduler, but I find this not very elegant.

Is there any good practice to do that ? (I've search the issues, but couldn't find...)

Thank you for your help :)
Mathieu.

I don’t think the gem supports that internally. What you suggest works well. You can create a class or rake task that has a sequence of operations to run that would execute sequentially.

Remember that these are cron jobs as well instead of other types of architecture. You can also create your own cron tab command through the gem and chain them by manually setting it as defined in the wiki.