mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-10-14 17:29:42 +00:00
Add handling and cleanup for expired export generations
Implemented a new cron job to identify and process expired export generations, dispatching messages for their removal. Added corresponding message handler, tests, and configuration updates to handle and orchestrate the deletion workflow.
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?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\Export\Messenger;
|
||||
|
||||
use Chill\MainBundle\Repository\ExportGenerationRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Clock\ClockInterface;
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
|
||||
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
|
||||
|
||||
#[AsMessageHandler]
|
||||
class RemoveExportGenerationMessageHandler implements MessageHandlerInterface
|
||||
{
|
||||
private const LOG_PREFIX = '[RemoveExportGenerationMessageHandler] ';
|
||||
|
||||
public function __construct(
|
||||
private ExportGenerationRepository $exportGenerationRepository,
|
||||
private EntityManagerInterface $entityManager,
|
||||
private LoggerInterface $logger,
|
||||
private ClockInterface $clock,
|
||||
) {}
|
||||
|
||||
public function __invoke(RemoveExportGenerationMessage $message): void
|
||||
{
|
||||
$exportGeneration = $this->exportGenerationRepository->find($message->exportGenerationId);
|
||||
|
||||
if (null === $exportGeneration) {
|
||||
$this->logger->error(self::LOG_PREFIX.'ExportGeneration not found');
|
||||
throw new UnrecoverableMessageHandlingException(self::LOG_PREFIX.'ExportGeneration not found');
|
||||
}
|
||||
|
||||
$storedObject = $exportGeneration->getStoredObject();
|
||||
$storedObject->setDeleteAt($this->clock->now());
|
||||
|
||||
$this->entityManager->remove($exportGeneration);
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user