@@ -187,22 +187,72 @@ Then, define the trigger date/time using the same syntax as the
187
187
// optionally you can define the timezone used by the cron expression
188
188
RecurringMessage::cron('* * * * *', new Message(), new \DateTimeZone('Africa/Malabo'));
189
189
190
+ .. tip ::
191
+
192
+ Check out the `crontab.guru website `_ if you need help to construct/understand
193
+ cron expressions.
194
+
190
195
You can also use some special values that represent common cron expressions:
191
196
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 * * * * ``
197
202
198
203
For example::
199
204
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
+ ====================== ========================================================================
201
243
202
- .. tip ::
244
+ For example ::
203
245
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
206
256
207
257
Periodical Triggers
208
258
~~~~~~~~~~~~~~~~~~~
0 commit comments