mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-11-22 03:47:48 +00:00
Feature: [docgen] generate documents in an async queue
The documents are now generated in a queue, using symfony messenger. This queue should be configured:
```yaml
# app/config/messenger.yaml
framework:
messenger:
# reset services after consuming messages
# reset_on_message: true
failure_transport: failed
transports:
# https://symfony.com/doc/current/messenger.html#transport-configuration
async: '%env(MESSENGER_TRANSPORT_DSN)%'
priority:
dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
failed: 'doctrine://default?queue_name=failed'
routing:
# ... other messages
'Chill\DocGeneratorBundle\Service\Messenger\RequestGenerationMessage': priority
```
`StoredObject`s now have additionnal properties:
* status (pending, failure, ready (by default) ), which explain if the document is generated;
* a generationTrialCounter, which is incremented on each generation trial, which prevent each generation more than 5 times;
The generator computation is moved from the `DocGenTemplateController` to a `Generator` (implementing `GeneratorInterface`.
There are new methods to `Context` which allow to normalize/denormalize context data to/from a messenger's `Message`.
This commit is contained in:
@@ -41,12 +41,6 @@ class StoredObject implements AsyncFileInterface, Document, TrackCreationInterfa
|
||||
|
||||
use TrackCreationTrait;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="datetime", name="creation_date")
|
||||
* @Serializer\Groups({"read", "write"})
|
||||
*/
|
||||
private DateTimeInterface $creationDate;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="json", name="datas")
|
||||
* @Serializer\Groups({"read", "write"})
|
||||
@@ -87,7 +81,7 @@ class StoredObject implements AsyncFileInterface, Document, TrackCreationInterfa
|
||||
private string $title = '';
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="text", name="type")
|
||||
* @ORM\Column(type="text", name="type", options={"default": ""})
|
||||
* @Serializer\Groups({"read", "write"})
|
||||
*/
|
||||
private string $type = '';
|
||||
@@ -105,9 +99,20 @@ class StoredObject implements AsyncFileInterface, Document, TrackCreationInterfa
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="text", options={"default": "ready"})
|
||||
* @Serializer\Groups({"read"})
|
||||
*/
|
||||
private string $status;
|
||||
|
||||
/**
|
||||
* Store the number of times a generation has been tryied for this StoredObject.
|
||||
*
|
||||
* This is a workaround, as generation consume lot of memory, and out-of-memory errors
|
||||
* are not handled by messenger.
|
||||
*
|
||||
* @ORM\Column(type="integer", options={"default": 0})
|
||||
*/
|
||||
private int $generationTrialsCounter = 0;
|
||||
|
||||
/**
|
||||
* @param StoredObject::STATUS_* $status
|
||||
*/
|
||||
@@ -117,8 +122,16 @@ class StoredObject implements AsyncFileInterface, Document, TrackCreationInterfa
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
public function addGenerationTrial(): self
|
||||
{
|
||||
$this->generationTrialsCounter++;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Serializer\Groups({"read", "write"})
|
||||
* @deprecated
|
||||
*/
|
||||
public function getCreationDate(): DateTime
|
||||
{
|
||||
@@ -135,6 +148,11 @@ class StoredObject implements AsyncFileInterface, Document, TrackCreationInterfa
|
||||
return $this->filename;
|
||||
}
|
||||
|
||||
public function getGenerationTrialsCounter(): int
|
||||
{
|
||||
return $this->generationTrialsCounter;
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
@@ -158,6 +176,9 @@ class StoredObject implements AsyncFileInterface, Document, TrackCreationInterfa
|
||||
return $this->getFilename();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return StoredObject::STATUS_*
|
||||
*/
|
||||
public function getStatus(): string
|
||||
{
|
||||
return $this->status;
|
||||
@@ -185,6 +206,7 @@ class StoredObject implements AsyncFileInterface, Document, TrackCreationInterfa
|
||||
|
||||
/**
|
||||
* @Serializer\Groups({"write"})
|
||||
* @deprecated
|
||||
*/
|
||||
public function setCreationDate(DateTime $creationDate): self
|
||||
{
|
||||
@@ -244,4 +266,30 @@ class StoredObject implements AsyncFileInterface, Document, TrackCreationInterfa
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTemplate(): ?DocGeneratorTemplate
|
||||
{
|
||||
return $this->template;
|
||||
}
|
||||
|
||||
public function hasTemplate(): bool
|
||||
{
|
||||
return null !== $this->template;
|
||||
}
|
||||
|
||||
public function setTemplate(?DocGeneratorTemplate $template): StoredObject
|
||||
{
|
||||
$this->template = $template;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isPending(): bool
|
||||
{
|
||||
return self::STATUS_PENDING === $this->getStatus();
|
||||
}
|
||||
|
||||
public function isFailure(): bool
|
||||
{
|
||||
return self::STATUS_FAILURE === $this->getStatus();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user