Skip to content

Commit 39748b8

Browse files
[Scheduler] Mention DateIntervalTrigger and DatePeriodTrigger
1 parent 77a60cd commit 39748b8

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

scheduler.rst

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,37 @@ defined by PHP datetime functions::
165165
$until = '2023-06-12';
166166
RecurringMessage::every('first Monday of next month', new Message(), $from, $until);
167167

168-
Custom Triggers
169-
~~~~~~~~~~~~~~~
168+
Triggers
169+
~~~~~~~~
170170

171+
Triggers allow to configure the frequency of a recurring message. The Scheduler
172+
component comes with two implementations of the
173+
:class:`Symfony\\Component\\Scheduler\\TriggerInterface`
174+
which you can use directly and will cover most use cases::
175+
176+
use Symfony\Component\Scheduler\Trigger\DateIntervalTrigger;
177+
use Symfony\Component\Scheduler\Trigger\DatePeriodTrigger;
178+
179+
$trigger = new DateIntervalTrigger('2 minutes', '2024-01-01', '2024-12-31');
180+
181+
// you can also pass an integer as the first argument, which will be interpreted as the interval in seconds
182+
$trigger = new DateIntervalTrigger(120, '2024-01-01', '2024-12-31');
183+
184+
// you can also omit the start date to use the current date, and/or omit the end date to have no end date
185+
$trigger = new DateIntervalTrigger('2 minutes');
186+
187+
// you can also create a trigger from a DatePeriod by using the DatePeriodTrigger
188+
$datePeriod = new DatePeriod(
189+
new DateTimeImmutable('2024-01-01'),
190+
new DateInterval('P1D'),
191+
new DateTimeImmutable('2024-12-31'),
192+
);
193+
194+
$trigger = new DatePeriodTrigger($datePeriod);
195+
196+
If these triggers don't cover your use cases, you can create custom triggers.
171197
Custom triggers allow to configure any frequency dynamically. They are created
172-
as services that implement :class:`Symfony\\Component\\Scheduler\\TriggerInterface`.
198+
as services that also implement :class:`Symfony\\Component\\Scheduler\\TriggerInterface`.
173199

174200
For example, if you want to send customer reports daily except for holiday periods::
175201

0 commit comments

Comments
 (0)