Skip to content

Commit d52717b

Browse files
committed
minor #20982 [Scheduler] Add runtime schedule modification feature to docs (Spomky)
This PR was merged into the 6.4 branch. Discussion ---------- [Scheduler] Add runtime schedule modification feature to docs This PR addresses #18929. It documents the new feature introduced in Symfony 6.4 that allows schedules to be modified dynamically at runtime. Friendly ping `@Jeroeny` 👋 Commits ------- def8d6b Add runtime schedule modification feature to docs
2 parents 7dfeaba + def8d6b commit d52717b

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

scheduler.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,46 @@ code::
890890
use the ``messenger:consume`` command as explained in the previous
891891
section.
892892

893+
Modifying the Schedule at Runtime
894+
---------------------------------
895+
896+
.. versionadded:: 6.4
897+
898+
Modifying the schedule at runtime and recalculating the heap was introduced in Symfony 6.4.
899+
900+
When a recurring message is added to or removed from the schedule,
901+
the scheduler automatically restarts and recalculates the internal trigger heap.
902+
This allows dynamic control over scheduled tasks during runtime.
903+
code::
904+
905+
// src/Scheduler/DynamicScheduleProvider.php
906+
namespace App\Scheduler;
907+
908+
#[AsSchedule('uptoyou')]
909+
class DynamicScheduleProvider implements ScheduleProviderInterface
910+
{
911+
private ?Schedule $schedule = null;
912+
913+
public function getSchedule(): Schedule
914+
{
915+
return $this->schedule ??= (new Schedule())
916+
->with(
917+
// ...
918+
)
919+
;
920+
}
921+
922+
public function clearAndAddMessages(): void
923+
{
924+
// Clear the current schedule (if any) and add new recurring messages
925+
$this->schedule?->clear();
926+
$this->schedule?->add(
927+
RecurringMessage::cron('@hourly', new DoActionMessage()),
928+
RecurringMessage::cron('@daily', new DoAnotherActionMessage()),
929+
);
930+
}
931+
}
932+
893933
Debugging the Schedule
894934
----------------------
895935

0 commit comments

Comments
 (0)