Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf85c683

Browse files
committed
Add runtime schedule modification feature to docs
Document the new ability introduced in Symfony 6.4 to modify schedules dynamically at runtime. This includes recalculating the internal trigger heap for better control over recurring tasks.
1 parent6556d97 commitf85c683

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)

[8]ページ先頭

©2009-2025 Movatter.jp