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 @@ -861,6 +861,46 @@ code::
861
861
use the ``messenger:consume `` command as explained in the previous
862
862
section.
863
863
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
+
864
904
Debugging the Schedule
865
905
----------------------
866
906
You can’t perform that action at this time.
0 commit comments