docGeneratorTemplateRepository = $docGeneratorTemplateRepository; $this->entityManager = $entityManager; $this->generator = $generator; $this->storedObjectRepository = $storedObjectRepository; } public function __invoke(RequestGenerationMessage $message) { if (null === $template = $this->docGeneratorTemplateRepository->find($message->getTemplateId())) { throw new \RuntimeException('template not found: ' . $message->getTemplateId()); } if (null === $destinationStoredObject = $this->storedObjectRepository->find($message->getDestinationStoredObjectId())) { throw new \RuntimeException('destination stored object not found : ' . $message->getDestinationStoredObjectId()); } if ($destinationStoredObject->getGenerationTrialsCounter() >= self::AUTHORIZED_TRIALS) { throw new UnrecoverableMessageHandlingException('maximum number of retry reached'); } $destinationStoredObject->addGenerationTrial(); $this->entityManager->createQuery('UPDATE '.StoredObject::class.' s SET s.generationTrialsCounter = s.generationTrialsCounter + 1 WHERE s.id = :id') ->setParameter('id', $destinationStoredObject->getId()) ->execute(); $this->generator->generateDocFromTemplate( $template, $message->getEntityId(), $message->getContextGenerationData(), $destinationStoredObject ); } }