Skip to content

Commit 91723a0

Browse files
committed
Merge branch '6.4' into 7.2
* 6.4: Minor tweaks Add runtime schedule modification feature to docs
2 parents ece1723 + e37d364 commit 91723a0

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
@@ -861,6 +861,46 @@ code::
861861
use the ``messenger:consume`` command as explained in the previous
862862
section.
863863

864+
Modifying the Schedule at Runtime
865+
---------------------------------
866+
867+
.. versionadded:: 6.4
868+
869+
Support for modifying the schedule at runtime and recalculating the heap
870+
was introduced in Symfony 6.4.
871+
872+
When a recurring message is added to or removed from the schedule,
873+
the scheduler automatically restarts and recalculates the internal trigger heap.
874+
This enables dynamic control of scheduled tasks at runtime::
875+
876+
// src/Scheduler/DynamicScheduleProvider.php
877+
namespace App\Scheduler;
878+
879+
#[AsSchedule('uptoyou')]
880+
class DynamicScheduleProvider implements ScheduleProviderInterface
881+
{
882+
private ?Schedule $schedule = null;
883+
884+
public function getSchedule(): Schedule
885+
{
886+
return $this->schedule ??= (new Schedule())
887+
->with(
888+
// ...
889+
)
890+
;
891+
}
892+
893+
public function clearAndAddMessages(): void
894+
{
895+
// clear the current schedule and add new recurring messages
896+
$this->schedule?->clear();
897+
$this->schedule?->add(
898+
RecurringMessage::cron('@hourly', new DoActionMessage()),
899+
RecurringMessage::cron('@daily', new DoAnotherActionMessage()),
900+
);
901+
}
902+
}
903+
864904
Debugging the Schedule
865905
----------------------
866906

0 commit comments

Comments
 (0)