@@ -501,6 +501,103 @@ before being further redispatched to its corresponding handler::
501501 }
502502 }
503503
504+ Scheduler Events
505+ ----------------
506+
507+ PreRunEvent
508+ ~~~~~~~~~~~
509+
510+ **Event Class **: :class: `Symfony\\ Component\\ Scheduler\\ Event\\ PreRunEvent `
511+
512+ ``PreRunEvent `` allows to modify the :class: `Symfony\\ Component\\ Scheduler\\ Schedule `
513+ or cancel message before it's consumed::
514+
515+ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
516+ use Symfony\Component\Scheduler\Event\PreRunEvent;
517+
518+ public function onMessage(PreRunEvent $event): void
519+ {
520+ $schedule = $event->getSchedule();
521+ $context = $event->getMessageContext();
522+ $message = $event->getMessage();
523+
524+ // do something with the schedule, context or message
525+
526+ // and/or cancel message
527+ $event->shouldCancel(true);
528+ }
529+
530+ Execute this command to find out which listeners are registered for this event
531+ and their priorities:
532+
533+ .. code-block :: terminal
534+
535+ $ php bin/console debug:event-dispatcher "Symfony\Component\Scheduler\Event\PreRunEvent"
536+
537+ PostRunEvent
538+ ~~~~~~~~~~~~
539+
540+ **Event Class **: :class: `Symfony\\ Component\\ Scheduler\\ Event\\ PostRunEvent `
541+
542+ ``PostRunEvent `` allows to modify the :class: `Symfony\\ Component\\ Scheduler\\ Schedule `
543+ after message is consumed::
544+
545+ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
546+ use Symfony\Component\Scheduler\Event\PostRunEvent;
547+
548+ public function onMessage(PostRunEvent $event): void
549+ {
550+ $schedule = $event->getSchedule();
551+ $context = $event->getMessageContext();
552+ $message = $event->getMessage();
553+
554+ // do something with the schedule, context or message
555+ }
556+
557+ Execute this command to find out which listeners are registered for this event
558+ and their priorities:
559+
560+ .. code-block :: terminal
561+
562+ $ php bin/console debug:event-dispatcher "Symfony\Component\Scheduler\Event\PostRunEvent"
563+
564+ FailureEvent
565+ ~~~~~~~~~~~~
566+
567+ **Event Class **: :class: `Symfony\\ Component\\ Scheduler\\ Event\\ FailureEvent `
568+
569+ ``FailureEvent `` allows to modify the :class: `Symfony\\ Component\\ Scheduler\\ Schedule `
570+ when message consumption throw an exception::
571+
572+ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
573+ use Symfony\Component\Scheduler\Event\FailureEvent;
574+
575+ public function onMessage(FailureEvent $event): void
576+ {
577+ $schedule = $event->getSchedule();
578+ $context = $event->getMessageContext();
579+ $message = $event->getMessage();
580+
581+ $error = $event->getError();
582+
583+ // do something with the schedule, context, message or error (logging, ...)
584+
585+ // and/or ignore failure event
586+ $event->shouldIgnore(true);
587+ }
588+
589+ Execute this command to find out which listeners are registered for this event
590+ and their priorities:
591+
592+ .. code-block :: terminal
593+
594+ $ php bin/console debug:event-dispatcher "Symfony\Component\Scheduler\Event\FailureEvent"
595+
596+ .. versionadded :: 6.4
597+
598+ Methods ``PreRunEvent ``, ``PostRunEvent `` and ``FailureEvent `` were introduced
599+ in Symfony 6.4.
600+
504601.. _`Memoizing` : https://en.wikipedia.org/wiki/Memoization
505602.. _`cron command-line utility` : https://en.wikipedia.org/wiki/Cron
506603.. _`crontab.guru website` : https://crontab.guru/
0 commit comments