logger = $context->getLogger(); $this->interruptConsumption = false; } public function onPreConsume(PreConsume $context): void { $this->logger = $context->getLogger(); if ($this->shouldBeStopped($context->getLogger())) { $context->interruptExecution(); } } public function onPostMessageReceived(PostMessageReceived $context): void { if ($this->shouldBeStopped($context->getLogger())) { $context->interruptExecution(); } } public function onPostConsume(PostConsume $context): void { if ($this->shouldBeStopped($context->getLogger())) { $context->interruptExecution(); } } public function handleSignal(int $signal): void { if ($this->logger) { $this->logger->debug(sprintf('[SignalExtension] Caught signal: %s', $signal)); } switch ($signal) { case \SIGTERM: // 15 : supervisor default stop case \SIGQUIT: // 3 : kill -s QUIT case \SIGINT: // 2 : ctrl+c if ($this->logger) { $this->logger->debug('[SignalExtension] Interrupt consumption'); } $this->interruptConsumption = true; break; default: break; } } private function shouldBeStopped(LoggerInterface $logger): bool { if ($this->interruptConsumption) { $logger->debug('[SignalExtension] Interrupt execution'); $this->interruptConsumption = false; return true; } return false; } }