Skip to content

How to execute multiple tasks with a single runner ? #835

@mbautista

Description

@mbautista

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions