schedule-bundle icon indicating copy to clipboard operation
schedule-bundle copied to clipboard

Running multiple scheduler commands for different tasks?

Open Kalyse opened this issue 4 years ago • 2 comments

This is going to sound totally whack, but I have intermittent issues with certain command runs failing. It only happens when the stars align, and multiple tasks run under the same scheduler run. I can't figure out the reproduction conditions, but if you imagine I have the hypothetical:

*/5 * * * * task1 */10 * * * * task2

          • task3
  • 0 * * * task4 30 0 * * * task5

What ends up happening, is on ten minute intervals task1, task2, task3 will run together, every 10 minutes, (they share the same common demonitor). On half hours, at midnight, task 4+5 will also run...

You get the idea - anyway, what ends up happening is my Unit of Work with Entity Manager is obviously getting screwed up by my own user-space code and it closes the Entity Manager causing weird problems and essentially commands which might end up never being ran.

It's isn't reproducible so I can't exactly nail down how to fix, but what I'd like to do is actually run the scheduler such that I run scheduler:run but instead of grabbing any task ready to run, it is limited to only task1 and task2 for one cron. Then I might have another scheduler:run which is only going to run task3 and task4.

Is this something that's currently possible? (I have a worry that it might have problems due to the cache lock factory so likely isn't possible).

My thinking is If I could isolate groups of tasks, I am hoping I can figure out which causes the underlying problem. Other ideas and suggestions are also welcome.

Kalyse avatar Feb 24 '21 15:02 Kalyse

I think I understand and I believe this is similar to #6. Some possible solutions:

  1. Can you play with the schedule at all to ensure they are all offset by at least a minute? (This is what I do)
  2. If these are CommandTask's, can you wrap them in a ProcessTask - this will ensure they run in separate processes
  3. If using symfony/messenger and you have an async transport, the MessageTask could queue the work to be done by your worker process.

Could any of the above work for you?

kbond avatar Feb 24 '21 16:02 kbond

Wow. Literally all three will work for me. Thanks for thinking outside the box. Will implement tomorrow and watch logs.

On Wed, Feb 24, 2021, 16:03 Kevin Bond [email protected] wrote:

I think I understand and I believe this is similar to #6 https://github.com/zenstruck/schedule-bundle/issues/6. Some possible solutions:

  1. Can you play with the schedule at all to ensure they are all offset by at least a minute? (This is what I do)
  2. If these are CommandTask's, can you wrap them in a ProcessTask - this will ensure they run in separate processes
  3. If using symfony/messenger and you have an async transport, the MessageTask could queue the work to be done by your worker process.

Could any of the above work for you?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/zenstruck/schedule-bundle/issues/36#issuecomment-785181838, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABQYUB4TBGCFQLKVNEJELDTAUPMLANCNFSM4YEWASSQ .

Kalyse avatar Feb 24 '21 17:02 Kalyse