Skip to content

Commit 41f1786

Browse files
eltharinjaviereguiluz
authored andcommitted
[Scheduler] Add capability to skip missed periodic tasks, only the last schedule will be called
1 parent f1c7127 commit 41f1786

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

scheduler.rst

+21
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,27 @@ This allows the system to retain the state of the schedule, ensuring that when a
889889
}
890890
}
891891

892+
With ``stateful`` option, All missed messages will be handled, If you nedd handle your message only once you can use the ``processOnlyLastMissedRun`` option.::
893+
894+
// src/Scheduler/SaleTaskProvider.php
895+
namespace App\Scheduler;
896+
897+
#[AsSchedule('uptoyou')]
898+
class SaleTaskProvider implements ScheduleProviderInterface
899+
{
900+
public function getSchedule(): Schedule
901+
{
902+
$this->removeOldReports = RecurringMessage::cron('3 8 * * 1', new CleanUpOldSalesReport());
903+
904+
return $this->schedule ??= (new Schedule())
905+
->with(
906+
// ...
907+
)
908+
->stateful($this->cache)
909+
->processOnlyLastMissedRun(true)
910+
}
911+
}
912+
892913
To scale your schedules more effectively, you can use multiple workers. In such
893914
cases, a good practice is to add a :doc:`lock </components/lock>` to prevent the
894915
same task more than once::

0 commit comments

Comments
 (0)