File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -866,6 +866,46 @@ code::
866
866
use the ``messenger:consume `` command as explained in the previous
867
867
section.
868
868
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
+
869
909
Debugging the Schedule
870
910
----------------------
871
911
You can’t perform that action at this time.
0 commit comments