-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Scheduler] Caching does not work for multiple messages in same schedule #51384
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
Comments
I tried stateful schedule for the first time and it seems to have very strange behavior indeed. (new Schedule())
->stateful($this->cache)
->add(RecurringMessage::every(1, new TestMessage('every 1 seconds')))
->add(RecurringMessage::every(4, new TestMessage('every 4 seconds'))) When continuing on a cached state:
"every 4 seconds" is one second apart at startup, then it goes back to "normal" though.
That's one solution, other seems to be
I did manage to make it work, however, it's a lot of breaking changes and I'm not sure if that's the way to go. About number 1, I think it should be done regardless. Now it's quite unexpected that messages in a Schedule will have different
IMO microseconds in both messages should be the same since I have not defined a |
@StanJansen, can you confirm if #51651 solves this issue? |
This PR was merged into the 6.4 branch. Discussion ---------- [Scheduler] Fix stateful scheduler | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #51646, #51384 | License | MIT Stateful scheduler seems rather broken at the moment, see #51384 (comment). Let's fix it by storing the original first run start time, that way it's always possible to recalculate the state. Catching-up works now: ``` [23:14:11.709710] Worker started [23:14:11.759318] every 2 seconds [23:14:11.760291] every 2 seconds [23:14:11.761257] every 2 seconds [23:14:11.763244] every 2 seconds [23:14:12.637054] every 2 seconds [23:14:14.620595] every 2 seconds [23:14:16.632170] every 2 seconds ``` Whereas before it would only start on from the current item, possibly skipping previous items like stated in #51646. _(is this a bc break?)_ I will be waiting for input from authors of the related issues. --- One test is failing because because `getNextRunDate` is called with `2020-02-20T01:59:00+02:00` and then next run date is expected at `2020-02-20T02:09:00+02:00` but we get `2020-02-20T02:00:00+02:00` because that's set as `from`. I don't quite get the logic, I would assume that it is expected to be run immediately on `from` :thinking: Commits ------- 2d5856b Fix stateful scheduler
This bug has been fixed in 6.4, not 6.3, as we had to introduce a BC break to fix it properly. |
Sorry for the late response but this indeed seems to fix it π₯³ |
Symfony version(s) affected
6.3
Description
When you have multiple messages in the same schedule, only the timestamp of the latest message will be saved in the cache. When your consumer stops (by
--time-limit
or unexpected) the next run date for the other messages will be calculated again. So when you have recurring messages for 1 minute and 30 minutes, with a restart policy of 60 seconds, the 30 minutes message will never be executed when you do do not pass thefrom
argument.As a temporary workaround I disabled jitter and set the
from
argument to a date in the past on 00:00:00, which makes the message be calculated based on that (so always on 00:30, 01:00 etc.). However if the consumer is restarting or down due to a crash at that moment, they will not be catched up when booting up the consumer again as the last-ran-date is not cached. This is why I disabled jitter to reduce that risk to the specific time instead of adding the jitter time to that.How to reproduce
MessageGenerator.php
Possible Solution
Edit the caching so it works per message, not per schedule.
Additional Context
I created a PR that got merged in 6.3.2 that fixed the
from
argument. This fixed the scheduler from executing 30 minute messages every minutely restart for example, but due to this bug that fix now causes those messages to never get executed. So unless you pass afrom
date, those schedules are completely broken at the moment.The text was updated successfully, but these errors were encountered: