<?php
namespace App\Event;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Messenger\Event\WorkerRunningEvent;
/**
* Class ExtractFailedEvent
*
* Required to call a Cron job:
* * * * * * bin/console messenger:consume lectures failed --memory-limit=128M --time-limit=3600
*
* Used to avoid to install the Supervisor in the server and create a config file for each project/queue
*/
class CronRunningEvent implements EventSubscriberInterface
{
public function onWorkerRunning(WorkerRunningEvent $event): void
{
// Returns true when no message has been received by the worker.
// If no message has been received , we stop the worker
if ($event->isWorkerIdle()){
$event->getWorker()->stop();
}
}
/**
* @return array<string>
*/
public static function getSubscribedEvents()
{
return [
WorkerRunningEvent::class => 'onWorkerRunning',
];
}
}