'onMessageFailed', ]; } public function onMessageFailed(WorkerMessageFailedEvent $event): void { if ($event->willRetry()) { return; } if (!$event->getEnvelope()->getMessage() instanceof RequestGenerationMessage) { return; } /** @var RequestGenerationMessage $message */ $message = $event->getEnvelope()->getMessage(); $this->logger->error(self::LOG_PREFIX.'Docgen failed', [ 'stored_object_id' => $message->getDestinationStoredObjectId(), 'entity_id' => $message->getEntityId(), 'template_id' => $message->getTemplateId(), 'creator_id' => $message->getCreatorId(), 'throwable_class' => $event->getThrowable()::class, ]); $this->markObjectAsFailed($message); $this->warnCreator($message, $event); } private function markObjectAsFailed(RequestGenerationMessage $message): void { $object = $this->storedObjectRepository->find($message->getDestinationStoredObjectId()); if (null === $object) { $this->logger->error(self::LOG_PREFIX.'Stored object not found', ['stored_object_id', $message->getDestinationStoredObjectId()]); } $object->setStatus(StoredObject::STATUS_FAILURE); $this->entityManager->flush(); } private function warnCreator(RequestGenerationMessage $message, WorkerMessageFailedEvent $event): void { $creatorId = $message->getCreatorId(); if (null === $creator = $this->userRepository->find($creatorId)) { $this->logger->error(self::LOG_PREFIX.'Creator not found with given id', ['creator_id', $creatorId]); return; } if (null === $creator->getEmail() || '' === $creator->getEmail()) { $this->logger->info(self::LOG_PREFIX.'Creator does not have any email', ['user' => $creator->getUsernameCanonical()]); return; } // if the exception is not a GeneratorException, we try the previous one... $throwable = $event->getThrowable(); if (!$throwable instanceof GeneratorException) { $throwable = $throwable->getPrevious(); } if ($throwable instanceof GeneratorException) { $errors = $throwable->getErrors(); } else { $errors = [$throwable->getTraceAsString()]; } if (null === $template = $this->docGeneratorTemplateRepository->find($message->getTemplateId())) { $this->logger->info(self::LOG_PREFIX.'Template not found', ['template_id' => $message->getTemplateId()]); return; } $email = (new TemplatedEmail()) ->to($creator->getEmail()) ->subject($this->translator->trans('docgen.failure_email.The generation of a document failed')) ->textTemplate('@ChillDocGenerator/Email/on_generation_failed_email.txt.twig') ->context([ 'errors' => $errors, 'template' => $template, 'creator' => $creator, 'stored_object_id' => $message->getDestinationStoredObjectId(), ]); $this->mailer->send($email); } }