-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Scheduler] Allow modifying the schedule at runtime and recalculate heap #51553
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
Conversation
Interesting, is this a companion PR for #51542? |
@kbond they don't depend on each other. But when both of them are merged, it enables a lot of capabilities for the Scheduler. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some usage example in the PR description?
@@ -10,6 +10,7 @@ CHANGELOG | |||
* Add `AbstractTriggerDecorator` | |||
* Make `ScheduledStamp` "send-able" | |||
* Add `ScheduledStamp` to `RedispatchMessage` | |||
* Allow modifying the Schedule at runtime |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Allow modifying the Schedule at runtime | |
* Allow modifying Schedule instances at runtime |
Thank you @Jeroeny. |
This PR was merged into the 6.4 branch. Discussion ---------- [Scheduler] pre_run and post_run events | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | #49803 (comment) | License | MIT Based on #49803 `@kbond` and taking into account #51553 The aim of this PR is to be able to act on the accumulated messages 'if something happens' and to be able to recalculate the heap via events (currently pre_run and post_run). The aim is to have access to - the the schedule and therefore add/cancel a certain type of message. - MessageContexte (e.g. access the id) - The message itself This PR would complement `@Jeroeny` #51553 PR by enabling action via events. Commits ------- 20fd21a [Scheduler] add PRE_RUN and POST_RUN events
Hi ! Do you have any examples of use? And as far as I understand, there's no documentation for this feature. |
@fabpot I'm also looking for an example, currently i uses this Doctrine Query to build the Schedule public function getSchedule(): Schedule
{
$result = new Schedule();
$repo = $this->manager->getRepository(Terminal::class);
$q = $repo->createQueryBuilder('t');
$q->where('t.status = true AND t.automatic = true');
foreach ($q->getQuery()->getResult() as $r) {
/**
* @var Terminal $r
*/
$result->add(RecurringMessage::cron(
$r->getCronExpr(),
new KassenschlussTask($r->getId()),
$this->timezoneDetector->getTimezone())
);
}
return $result;
} because each object might have its own CronExpr, each of them needs its own RecurringMessage and how do i handle if they get disabled? |
@Sophikitis while maybe not the best way, i found $cacheItem = $this->restartSignalCachePool->getItem(StopWorkerOnRestartSignalListener::RESTART_REQUESTED_TIMESTAMP_KEY);
$cacheItem->set(microtime(true));
$this->restartSignalCachePool->save($cacheItem); i used |
Schedules are created statically by a ScheduleProviderInterface. This is nice if you have a small app with some predetermined scheduled actions. But if you want to schedule business logic dynamically, e.g. have admins Crud a schedule in the DB, then the schedule needs to be updateable at runtime. This also allows for the app to re-add schedules that have returned
null
as nextRunDate in the past (making them unscheduled) and to remove schedules.Usage example: reading the schedule from a DB repository, adding messages based on an custom event:
Or in the context of Messenger, if some periodic batch task has no more work to do, the recurring message can be removed: