src/Event/CronRunningEvent.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Event;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\Messenger\Event\WorkerRunningEvent;
  5. /**
  6.  * Class ExtractFailedEvent
  7.  *  
  8.  * Required to call a Cron job:
  9.  * * * * * * bin/console messenger:consume lectures failed --memory-limit=128M --time-limit=3600
  10.  * 
  11.  * Used to avoid to install the Supervisor in the server and create a config file for each project/queue
  12.  */
  13. class CronRunningEvent implements EventSubscriberInterface
  14. {
  15.     public function onWorkerRunning(WorkerRunningEvent $event): void
  16.     {
  17.         // Returns true when no message has been received by the worker.
  18.         // If no message has been received , we stop the worker
  19.         if ($event->isWorkerIdle()){
  20.             $event->getWorker()->stop();
  21.         }
  22.     }
  23.     /**
  24.      * @return array<string>
  25.      */
  26.     public static function getSubscribedEvents()
  27.     {
  28.         return [
  29.             WorkerRunningEvent::class => 'onWorkerRunning',
  30.         ];
  31.     }
  32. }