Skip to content

Commit 1dbad60

Browse files
committed
Merge branch '6.4' into 7.0
* 6.4: Tweaks [Scheduler] Document hashed Cron expression
2 parents 9fd9702 + 3683e22 commit 1dbad60

File tree

1 file changed

+59
-9
lines changed

1 file changed

+59
-9
lines changed

scheduler.rst

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,22 +187,72 @@ Then, define the trigger date/time using the same syntax as the
187187
// optionally you can define the timezone used by the cron expression
188188
RecurringMessage::cron('* * * * *', new Message(), new \DateTimeZone('Africa/Malabo'));
189189

190+
.. tip::
191+
192+
Check out the `crontab.guru website`_ if you need help to construct/understand
193+
cron expressions.
194+
190195
You can also use some special values that represent common cron expressions:
191196

192-
* ``#yearly``, ``#annually`` - Run once a year, midnight, Jan. 1 - ``0 0 1 1 *``
193-
* ``#monthly`` - Run once a month, midnight, first of month - ``0 0 1 * *``
194-
* ``#weekly`` - Run once a week, midnight on Sun - ``0 0 * * 0``
195-
* ``#daily``, ``#midnight`` - Run once a day, midnight - ``0 0 * * *``
196-
* ``#hourly`` - Run once an hour, first minute - ``0 * * * *``
197+
* ``@yearly``, ``@annually`` - Run once a year, midnight, Jan. 1 - ``0 0 1 1 *``
198+
* ``@monthly`` - Run once a month, midnight, first of month - ``0 0 1 * *``
199+
* ``@weekly`` - Run once a week, midnight on Sun - ``0 0 * * 0``
200+
* ``@daily``, ``@midnight`` - Run once a day, midnight - ``0 0 * * *``
201+
* ``@hourly`` - Run once an hour, first minute - ``0 * * * *``
197202

198203
For example::
199204

200-
RecurringMessage::cron('#daily', new Message());
205+
RecurringMessage::cron('@daily', new Message());
206+
207+
Hashed Cron Expressions
208+
·······················
209+
210+
If you have many triggers scheduled at same time (for example, at midnight, ``0 0 * * *``)
211+
this will create a very long running list of schedules at that exact time.
212+
This may cause an issue if a task has a memory leak.
213+
214+
You can add a hash symbol (``#``) in expressions to generate random values.
215+
Athough the values are random, they are predictable and consistent because they
216+
are generated based on the message. A message with string representation ``my task``
217+
and a defined frequency of ``# # * * *`` will have an idempotent frequency
218+
of ``56 20 * * *`` (every day at 8:56pm).
219+
220+
You can also use hash ranges (``#(x-y)``) to define the list of possible values
221+
for that random part. For example, ``# #(0-7) * * *`` means daily, some time
222+
between midnight and 7am. Using the ``#`` without a range creates a range of any
223+
valid value for the field. ``# # # # #`` is short for ``#(0-59) #(0-23) #(1-28)
224+
#(1-12) #(0-6)``.
225+
226+
You can also use some special values that represent common hashed cron expressions:
227+
228+
====================== ========================================================================
229+
Alias Converts to
230+
====================== ========================================================================
231+
``#hourly`` ``# * * * *`` (at some minute every hour)
232+
``#daily`` ``# # * * *`` (at some time every day)
233+
``#weekly`` ``# # * * #`` (at some time every week)
234+
``#weekly@midnight`` ``# #(0-2) * * #`` (at ``#midnight`` one day every week)
235+
``#monthly`` ``# # # * *`` (at some time on some day, once per month)
236+
``#monthly@midnight`` ``# #(0-2) # * *`` (at ``#midnight`` on some day, once per month)
237+
``#annually`` ``# # # # *`` (at some time on some day, once per year)
238+
``#annually@midnight`` ``# #(0-2) # # *`` (at ``#midnight`` on some day, once per year)
239+
``#yearly`` ``# # # # *`` alias for ``#annually``
240+
``#yearly@midnight`` ``# #(0-2) # # *`` alias for ``#annually@midnight``
241+
``#midnight`` ``# #(0-2) * * *`` (at some time between midnight and 2:59am, every day)
242+
====================== ========================================================================
201243

202-
.. tip::
244+
For example::
203245

204-
Check out the `crontab.guru website`_ if you need help to construct/understand
205-
cron expressions.
246+
RecurringMessage::cron('#midnight', new Message());
247+
248+
.. note::
249+
250+
The day of month range is ``1-28``, this is to account for February
251+
which has a minimum of 28 days.
252+
253+
.. versionadded:: 6.4
254+
255+
Since version 6.4, it is now possible to add and define a timezone as a 3rd argument
206256

207257
Periodical Triggers
208258
~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)