@@ -194,29 +194,72 @@ Then, define the trigger date/time using the same syntax as the
194
194
195
195
RecurringMessage::cron('* * * * *', new Message());
196
196
197
- // optionally you can define the timezone used by the cron expression
198
- RecurringMessage::cron('* * * * *', new Message(), new \DateTimeZone('Africa/Malabo'));
199
-
200
- .. versionadded :: 6.4
197
+ .. tip ::
201
198
202
- The feature to define the cron timezone was introduced in Symfony 6.4.
199
+ Check out the `crontab.guru website `_ if you need help to construct/understand
200
+ cron expressions.
203
201
204
202
You can also use some special values that represent common cron expressions:
205
203
206
- * ``# yearly ``, ``# annually `` - Run once a year, midnight, Jan. 1 - ``0 0 1 1 * ``
207
- * ``# monthly `` - Run once a month, midnight, first of month - ``0 0 1 * * ``
208
- * ``# weekly `` - Run once a week, midnight on Sun - ``0 0 * * 0 ``
209
- * ``# daily ``, ``# midnight `` - Run once a day, midnight - ``0 0 * * * ``
210
- * ``# hourly `` - Run once an hour, first minute - ``0 * * * * ``
204
+ * ``@ yearly ``, ``@ annually `` - Run once a year, midnight, Jan. 1 - ``0 0 1 1 * ``
205
+ * ``@ monthly `` - Run once a month, midnight, first of month - ``0 0 1 * * ``
206
+ * ``@ weekly `` - Run once a week, midnight on Sun - ``0 0 * * 0 ``
207
+ * ``@ daily ``, ``@ midnight `` - Run once a day, midnight - ``0 0 * * * ``
208
+ * ``@ hourly `` - Run once an hour, first minute - ``0 * * * * ``
211
209
212
210
For example::
213
211
214
- RecurringMessage::cron('#daily', new Message());
212
+ RecurringMessage::cron('@daily', new Message());
213
+
214
+ Hashed Cron Expressions
215
+ ·······················
216
+
217
+ If you have many triggers scheduled at same time (for example, at midnight, ``0 0 * * * ``)
218
+ this will create a very long running list of schedules at that exact time.
219
+ This may cause an issue if a task has a memory leak.
220
+
221
+ You can add a hash symbol (``# ``) in expressions to generate random values.
222
+ Athough the values are random, they are predictable and consistent because they
223
+ are generated based on the message. A message with string representation ``my task ``
224
+ and a defined frequency of ``# # * * * `` will have an idempotent frequency
225
+ of ``56 20 * * * `` (every day at 8:56pm).
226
+
227
+ You can also use hash ranges (``#(x-y) ``) to define the list of possible values
228
+ for that random part. For example, ``# #(0-7) * * * `` means daily, some time
229
+ between midnight and 7am. Using the ``# `` without a range creates a range of any
230
+ valid value for the field. ``# # # # # `` is short for ``#(0-59) #(0-23) #(1-28)
231
+ #(1-12) #(0-6) ``.
232
+
233
+ You can also use some special values that represent common hashed cron expressions:
234
+
235
+ ====================== ========================================================================
236
+ Alias Converts to
237
+ ====================== ========================================================================
238
+ ``#hourly `` ``# * * * * `` (at some minute every hour)
239
+ ``#daily `` ``# # * * * `` (at some time every day)
240
+ ``#weekly `` ``# # * * # `` (at some time every week)
241
+ ``#weekly@midnight `` ``# #(0-2) * * # `` (at ``#midnight `` one day every week)
242
+ ``#monthly `` ``# # # * * `` (at some time on some day, once per month)
243
+ ``#monthly@midnight `` ``# #(0-2) # * * `` (at ``#midnight `` on some day, once per month)
244
+ ``#annually `` ``# # # # * `` (at some time on some day, once per year)
245
+ ``#annually@midnight `` ``# #(0-2) # # * `` (at ``#midnight `` on some day, once per year)
246
+ ``#yearly `` ``# # # # * `` alias for ``#annually ``
247
+ ``#yearly@midnight `` ``# #(0-2) # # * `` alias for ``#annually@midnight ``
248
+ ``#midnight `` ``# #(0-2) * * * `` (at some time between midnight and 2:59am, every day)
249
+ ====================== ========================================================================
215
250
216
- .. tip ::
251
+ For example ::
217
252
218
- Check out the `crontab.guru website `_ if you need help to construct/understand
219
- cron expressions.
253
+ RecurringMessage::cron('#midnight', new Message());
254
+
255
+ .. note ::
256
+
257
+ The day of month range is ``1-28 ``, this is to account for February
258
+ which has a minimum of 28 days.
259
+
260
+ .. versionadded :: 6.4
261
+
262
+ Since version 6.4, it is now possible to add and define a timezone as a 3rd argument
220
263
221
264
Periodical Triggers
222
265
~~~~~~~~~~~~~~~~~~~
0 commit comments