@@ -93,6 +93,8 @@ Another important difference is that messages in the Scheduler component are
93
93
recurring. They are represented via the :class: `Symfony\\ Component\\ Scheduler\\ RecurringMessage `
94
94
class.
95
95
96
+ .. _scheduler_attaching-recurring-messages :
97
+
96
98
Attaching Recurring Messages to a Schedule
97
99
------------------------------------------
98
100
@@ -173,6 +175,8 @@ methods::
173
175
Most of them can be created via the :class: `Symfony\\ Component\\ Scheduler\\ RecurringMessage `
174
176
class, as shown in the following examples.
175
177
178
+ .. _scheduler_cron-expression-triggers :
179
+
176
180
Cron Expression Triggers
177
181
~~~~~~~~~~~~~~~~~~~~~~~~
178
182
@@ -211,6 +215,34 @@ For example::
211
215
Check out the `crontab.guru website `_ if you need help to construct/understand
212
216
cron expressions.
213
217
218
+ Another way of declaring cron triggers is to use the
219
+ :class: `Symfony\\ Component\\ Scheduler\\ Attribute\\ AsCronTask ` attribute
220
+ on an invokable class::
221
+
222
+ // src/Scheduler/Task/SendDailySalesReports.php
223
+ namespace App\Scheduler\Task;
224
+
225
+ use Symfony\Component\Scheduler\Attribute\AsCronTask;
226
+
227
+ #[AsCronTask('0 0 * * *')]
228
+ class SendDailySalesReports
229
+ {
230
+ public function __invoke()
231
+ {
232
+ // ...
233
+ }
234
+ }
235
+
236
+ If you want to use another method name than ``__invoke() ``, you can specify it
237
+ by setting the ``method `` parameter of the attribute.
238
+
239
+ .. versionadded :: 6.4
240
+
241
+ The :class: `Symfony\\ Component\\ Scheduler\\ Attribute\\ AsCronTask ` attribute
242
+ was introduced in Symfony 6.4.
243
+
244
+ .. _scheduler_periodical-triggers :
245
+
214
246
Periodical Triggers
215
247
~~~~~~~~~~~~~~~~~~~
216
248
@@ -226,6 +258,32 @@ defined by PHP datetime functions::
226
258
$until = '2023-06-12';
227
259
RecurringMessage::every('first Monday of next month', new Message(), $from, $until);
228
260
261
+ Like cron triggers, you can also use the
262
+ :class: `Symfony\\ Component\\ Scheduler\\ Attribute\\ AsPeriodicTask ` attribute
263
+ on an invokable class::
264
+
265
+ // src/Scheduler/Task/SendDailySalesReports.php
266
+ namespace App\Scheduler\Task;
267
+
268
+ use Symfony\Component\Scheduler\Attribute\AsPeriodicTask;
269
+
270
+ #[AsPeriodicTask(frequency: '1 day', from: '2022-01-01', until: '2023-06-12')]
271
+ class SendDailySalesReports
272
+ {
273
+ public function __invoke()
274
+ {
275
+ // ...
276
+ }
277
+ }
278
+
279
+ Or if you want to use another method name than ``__invoke() ``, you can specify it
280
+ by setting the ``method `` parameter of the attribute.
281
+
282
+ .. versionadded :: 6.4
283
+
284
+ The :class: `Symfony\\ Component\\ Scheduler\\ Attribute\\ AsPeriodicTask ` attribute
285
+ was introduced in Symfony 6.4.
286
+
229
287
Custom Triggers
230
288
~~~~~~~~~~~~~~~
231
289
0 commit comments