Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Scheduler] Periodical triggers timing #20447

Open
wants to merge 1 commit into
base: 6.4
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions scheduler.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <scheduler-attributes-periodic-task>`.

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.
Comment on lines +293 to +295
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
The message will be executed after the first frequency period
has passed.

Documentation are often easier to read when written in positive / direct tone. Here i think we should remove "be aware" or "only", "isnt".

(suggestion just for illustration)


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);
Comment on lines +297 to +313
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We tend to favor "documentation in code examples" over normal text. So I would suggest merging this into one code block and adding a couple inline comments, like:

// execute a message every day at 13:00
$from = new \DateTimeImmutable('13:00', new \DateTimeZone('Europe/Paris'));
RecurringMessage::every('1 day', new Message(), from: $from);

// execute a message every day until a specific date
$until = '2023-06-12';
RecurringMessage::every('1 day', new Message(), until: $until);

// ... etc


If you don't pass a from parameter to your schedule, the first frequency period
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can merge this paragraph with the first one you added, as it's saying the same thing?

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
~~~~~~~~~~~~~~~

Expand Down
Loading