Skip to content

Commit ecc94bb

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

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
@@ -866,6 +866,46 @@ code::
866866
use the ``messenger:consume`` command as explained in the previous
867867
section.
868868

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

0 commit comments

Comments
 (0)