From f58f1ebfa747a4aa900710abed46b0563f55fb76 Mon Sep 17 00:00:00 2001 From: Tim Goudriaan Date: Sat, 7 Dec 2024 11:53:08 +0100 Subject: [PATCH] [Scheduler] Periodical triggers timing --- scheduler.rst | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/scheduler.rst b/scheduler.rst index 160ba26e0cb..9407b85e57f 100644 --- a/scheduler.rst +++ b/scheduler.rst @@ -286,14 +286,37 @@ defined by PHP datetime functions:: RecurringMessage::every('3 weeks', new Message()); RecurringMessage::every('first Monday of next month', new Message()); - $from = new \DateTimeImmutable('13:47', new \DateTimeZone('Europe/Paris')); - $until = '2023-06-12'; - RecurringMessage::every('first Monday of next month', new Message(), $from, $until); - .. tip:: You can also define periodic tasks using :ref:`the AsPeriodicTask attribute `. +Be aware that the message isn't passed to the messenger when you start the +scheduler. The message will only be executed after the first frequency period +has passed. + +It's also possible to pass a from and until time for your schedule. For +example, if you want to execute a command every day at 13:00:: + + $from = new \DateTimeImmutable('13:00', new \DateTimeZone('Europe/Paris')); + RecurringMessage::every('1 day', new Message(), from: $from); + +Or if you want to execute a message every day until a specific date:: + + $until = '2023-06-12'; + RecurringMessage::every('1 day', new Message(), until: $until); + +And you can even combine the from and until parameters for more granular +control:: + + $from = new \DateTimeImmutable('2023-01-01 13:47', new \DateTimeZone('Europe/Paris')); + $until = '2023-06-12'; + RecurringMessage::every('first Monday of next month', new Message(), from: $from, until: $until); + +If you don't pass a from parameter to your schedule, the first frequency period +is counted from the moment the scheduler is started. So if you start your +scheduler at 8:33 and the message is scheduled to perform every hour, it +will be executed at 9:33, 10:33, 11:33 and so on. + Custom Triggers ~~~~~~~~~~~~~~~