feat: fragment messages to gain efficiency

This commit is contained in:
Maël Gangloff
2024-07-21 16:55:39 +02:00
parent 43c4c9a33d
commit 8a5f69c333
10 changed files with 261 additions and 135 deletions

View File

@@ -0,0 +1,35 @@
<?php
namespace App\MessageHandler;
use App\Entity\WatchList;
use App\Message\ProcessWatchListsTrigger;
use App\Message\ProcessWatchListTrigger;
use App\Repository\WatchListRepository;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\Exception\ExceptionInterface;
use Symfony\Component\Messenger\MessageBusInterface;
#[AsMessageHandler]
readonly final class ProcessWatchListsTriggerHandler
{
public function __construct(
private WatchListRepository $watchListRepository,
private MessageBusInterface $bus
)
{
}
/**
* @throws ExceptionInterface
*/
public function __invoke(ProcessWatchListsTrigger $message): void
{
/** @var WatchList $watchList */
foreach ($this->watchListRepository->findAll() as $watchList) {
$this->bus->dispatch(new ProcessWatchListTrigger($watchList->getToken()));
}
}
}