mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
37 lines
1.0 KiB
PHP
37 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\MessageHandler;
|
|
|
|
use App\Entity\WatchList;
|
|
use App\Message\ProcessWatchListsTrigger;
|
|
use App\Message\ProcessWatchListTrigger;
|
|
use App\Repository\WatchListRepository;
|
|
use Random\Randomizer;
|
|
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
|
use Symfony\Component\Messenger\Exception\ExceptionInterface;
|
|
use Symfony\Component\Messenger\MessageBusInterface;
|
|
|
|
#[AsMessageHandler]
|
|
final readonly class ProcessWatchListsTriggerHandler
|
|
{
|
|
public function __construct(
|
|
private WatchListRepository $watchListRepository,
|
|
private MessageBusInterface $bus
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* @throws ExceptionInterface
|
|
*/
|
|
public function __invoke(ProcessWatchListsTrigger $message): void
|
|
{
|
|
$randomizer = new Randomizer();
|
|
$watchLists = $randomizer->shuffleArray($this->watchListRepository->findAll());
|
|
|
|
/** @var WatchList $watchList */
|
|
foreach ($watchLists as $watchList) {
|
|
$this->bus->dispatch(new ProcessWatchListTrigger($watchList->getToken()));
|
|
}
|
|
}
|
|
}
|