I was worried about that, and it appears Symfony does not kill messenger consumers while a message is being handled, only after the message is handled.
This is true for all --limit, --memory-limit, --time-limit options.
Let’s look at the code of the messenger:consume command (source):
// when --limit$this->eventDispatcher->addSubscriber(new StopWorkerOnMessageLimitListener($limit, $this->logger)); // when --memory-limit$this->eventDispatcher->addSubscriber(new StopWorkerOnMemoryLimitListener($this->convertToBytes($memoryLimit), $this->logger)); // when --time-limit$this->eventDispatcher->addSubscriber(new StopWorkerOnTimeLimitListener($timeLimit, $this->logger));Subscirbers listen to the WorkerRunningEvent to stop the consumer (source):
class StopWorkerOnTimeLimitListener implements EventSubscriberInterface{ // ... public function onWorkerRunning(WorkerRunningEvent $event): void { if ($this->endTime < microtime(true)) { $event->getWorker()->stop(); } } public static function getSubscribedEvents(): array { return [ WorkerStartedEvent::class => 'onWorkerStarted', WorkerRunningEvent::class => 'onWorkerRunning', ]; }}WorkerRunningEvent says (source):
Dispatched after the worker processed a message or didn't receive a message at all.
So, Symfony does not kill a message while it’s being processed; Good!
Comments