Add async handling for signature state changes

Introduce MessageBus to handle post-signature operations asynchronously. This ensures that further steps are executed through dispatched messages, improving system scalability and performance. Implement new handlers and messages for the workflow state transitions.
This commit is contained in:
2024-09-25 11:58:41 +02:00
parent cfce531754
commit 5287824dbe
4 changed files with 86 additions and 4 deletions

View File

@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Workflow\Messenger;
use Chill\MainBundle\Repository\Workflow\EntityWorkflowStepSignatureRepository;
use Chill\MainBundle\Workflow\SignatureStepStateChanger;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
final readonly class PostSignatureStateChangeHandler implements MessageHandlerInterface
{
public function __construct(
private EntityWorkflowStepSignatureRepository $entityWorkflowStepSignatureRepository,
private SignatureStepStateChanger $signatureStepStateChanger,
private EntityManagerInterface $entityManager,
) {}
public function __invoke(PostSignatureStateChangeMessage $message): void
{
$signature = $this->entityWorkflowStepSignatureRepository->find($message->signatureId);
if (null === $signature) {
throw new UnrecoverableMessageHandlingException('signature not found');
}
$this->signatureStepStateChanger->onPostMark($signature);
$this->entityManager->flush();
$this->entityManager->clear();
}
}

View File

@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Workflow\Messenger;
/**
* Message which is dispatched after a notification has a step changed.
*/
class PostSignatureStateChangeMessage
{
public function __construct(
public int $signatureId,
) {}
}