src/EventSubscriber/AppWorkerSubscriber.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use Psr\Log\LoggerInterface;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\Messenger\Event\WorkerMessageFailedEvent;
  6. use Symfony\Component\Messenger\Exception\RejectRedeliveredMessageException;
  7. final class AppWorkerSubscriber implements EventSubscriberInterface
  8. {
  9.     private LoggerInterface $logger;
  10.     public function __construct(LoggerInterface $slackLogger)
  11.     {
  12.         $this->logger $slackLogger;
  13.     }
  14.     public static function getSubscribedEvents(): array
  15.     {
  16.         return [
  17.             WorkerMessageFailedEvent::class => 'onMessageFailed'
  18.         ];
  19.     }
  20.     public function onMessageFailed(WorkerMessageFailedEvent $event): void
  21.     {
  22.         $exception $event->getThrowable();
  23.         if (!$exception instanceof RejectRedeliveredMessageException) {
  24.             $this->logger->critical($exception->getMessage(), [
  25.                 'exception' => $exception,
  26.                 'receiver' => $event->getReceiverName()
  27.             ]);
  28.         }
  29.     }
  30. }