Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mbautista opened this issue Jan 30, 2023 · 1 comment
Open

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

mbautista opened this issue Jan 30, 2023 · 1 comment

Comments

@mbautista
Copy link

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.

@samholst
Copy link

samholst commented Apr 8, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants