params = $params; $this->mercureHubService = $mercureHubService; } public static function getSubscribedEvents() { return [ WorkerMessageFailedEvent::class => 'onMessageFailed' ]; } public function onMessageFailed(WorkerMessageFailedEvent $event) { $error = $event->getThrowable(); // HandlerFailedException $exceptionsArray = reset($error); // Exceptions array $exception = reset($exceptionsArray); // First Exception from array $exceptionClass = get_class($exception); // Exception class $envelope = $event->getEnvelope(); $message = $envelope->getMessage(); $messageClass = get_class($message); $lastStamp = $envelope->last(RedeliveryStamp::class); $retryCount = $this->params->get("messenger_max_retries"); $data = [ "error" => null, "userId" => null, "pageId" => null, "projectId" => null, "exportId" => null, "version" => null ]; $genericMessage = "Failed to"; switch ($messageClass) { case GenerationExecuteMessage::class: $data['userId'] = $message->getGenerationNotificationMessage()->getUserId(); $data['pageId'] = $message->getGenerationNotificationMessage()->getPageId(); $data['projectId'] = $message->getGenerationNotificationMessage()->getProjectId(); $data['exportId'] = $message->getGenerationNotificationMessage()->getExportId(); $data["error"] = "$genericMessage get Indesign's data"; $data['version'] = $message->getGenerationNotificationMessage()->getPageDuplicateId(); $topicPreview = $message->getGenerationNotificationMessage()->getGenerationType() != 2 ? $this->params->get('mercure_topic_preview') : $this->params->get('mercure_topic_package'); $this->mercureHubService->publish($topicPreview, $data); break; case GenerationNotificationMessage::class: $data['userId'] = $message->getUserId(); $data['pageId'] = $message->getPageId(); $data['projectId'] = $message->getProjectId(); $data['exportId'] = $message->getExportId(); $data['version'] = $message->getPageDuplicateId(); $operation = "cancelled"; if ($exceptionClass === UnrecoverableMessageHandlingException::class) { $verb = "save"; } else { $verb = "get"; if (!$lastStamp || !method_exists($lastStamp, 'getRetryCount') || $retryCount !== $lastStamp->getRetryCount()) { $operation = "new try ..."; } } $data["error"] = "$genericMessage $verb page's preview, $operation"; $topicPreview = $message->getGenerationType() != 2 ? $this->params->get('mercure_topic_preview') : $this->params->get('mercure_topic_package'); $this->mercureHubService->publish($topicPreview, $data); break; } } }