Compare commits
2 Commits
969f4569f5
...
feat/monit
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2289156f57 | ||
|
|
f42b5a9cf5 |
36
src/Command/RunMonitoringCommand.php
Normal file
36
src/Command/RunMonitoringCommand.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Command;
|
||||||
|
|
||||||
|
use App\Domain\Manga\Application\Command\CheckMonitoredMangas;
|
||||||
|
use Symfony\Component\Console\Attribute\AsCommand;
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Messenger\MessageBusInterface;
|
||||||
|
|
||||||
|
#[AsCommand(
|
||||||
|
name: 'app:monitoring:run',
|
||||||
|
description: 'Déclenche immédiatement la vérification des mangas monitorés (sans attendre le scheduler)',
|
||||||
|
)]
|
||||||
|
class RunMonitoringCommand extends Command
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly MessageBusInterface $commandBus,
|
||||||
|
) {
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
|
{
|
||||||
|
$output->writeln('Déclenchement du monitoring des mangas...');
|
||||||
|
|
||||||
|
$this->commandBus->dispatch(new CheckMonitoredMangas());
|
||||||
|
|
||||||
|
$output->writeln('<info>Vérification lancée. Les nouveaux chapitres détectés seront scrappés via le worker commands.</info>');
|
||||||
|
|
||||||
|
return Command::SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,26 +26,18 @@ readonly class RefreshMangaChaptersHandler
|
|||||||
throw new \RuntimeException('Manga not found');
|
throw new \RuntimeException('Manga not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synchronisation + récupération des numéros de nouveaux chapitres
|
// Synchronisation + récupération des nouveaux IDs
|
||||||
$newChapterNumbers = $this->chapterSynchronizationService->synchronizeChapters($manga);
|
$newChapterIds = $this->chapterSynchronizationService->synchronizeChapters($manga);
|
||||||
|
|
||||||
// Mise à jour de la date de monitoring
|
// Mise à jour de la date de monitoring
|
||||||
$manga->updateLastMonitoringCheck(new \DateTimeImmutable());
|
$manga->updateLastMonitoringCheck(new \DateTimeImmutable());
|
||||||
$this->mangaRepository->save($manga);
|
$this->mangaRepository->save($manga);
|
||||||
|
|
||||||
// Événement de scraping pour chaque nouveau chapitre
|
// Événement de scraping pour chaque nouveau chapitre
|
||||||
// On retrouve l'ID réel (PK integer) après save() car le chapitre n'a
|
foreach ($newChapterIds as $chapterId) {
|
||||||
// son identifiant définitif qu'une fois persisté en base.
|
$this->eventBus->dispatch(
|
||||||
foreach ($newChapterNumbers as $chapterNumber) {
|
new ChapterReadyForScraping(new ChapterId($chapterId))
|
||||||
$saved = $this->mangaRepository->findChapterByMangaIdAndNumber(
|
|
||||||
$manga->getId()->getValue(),
|
|
||||||
$chapterNumber
|
|
||||||
);
|
);
|
||||||
if ($saved) {
|
|
||||||
$this->eventBus->dispatch(
|
|
||||||
new ChapterReadyForScraping(new ChapterId($saved->getId()))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ interface ChapterSynchronizationServiceInterface
|
|||||||
/**
|
/**
|
||||||
* Synchronise les chapitres d'un manga depuis la source externe.
|
* Synchronise les chapitres d'un manga depuis la source externe.
|
||||||
*
|
*
|
||||||
* @return float[] Numéros des nouveaux chapitres ajoutés
|
* @return string[] IDs des nouveaux chapitres ajoutés
|
||||||
*/
|
*/
|
||||||
public function synchronizeChapters(Manga $manga): array;
|
public function synchronizeChapters(Manga $manga): array;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Manga\Infrastructure\CommandHandler;
|
||||||
|
|
||||||
|
use App\Domain\Manga\Application\Command\CheckMonitoredMangas;
|
||||||
|
use App\Domain\Manga\Application\CommandHandler\CheckMonitoredMangasHandler;
|
||||||
|
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||||
|
|
||||||
|
#[AsMessageHandler]
|
||||||
|
readonly class SymfonyCheckMonitoredMangasHandler
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private CheckMonitoredMangasHandler $handler,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __invoke(CheckMonitoredMangas $command): void
|
||||||
|
{
|
||||||
|
$this->handler->handle($command);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -96,11 +96,11 @@ readonly class MangadxChapterSynchronizationService implements ChapterSynchroniz
|
|||||||
|
|
||||||
$newChapterIds = [];
|
$newChapterIds = [];
|
||||||
|
|
||||||
// Sauvegarde uniquement les nouveaux chapitres et collecte leurs numéros
|
// Sauvegarde uniquement les nouveaux chapitres et collecte leurs IDs
|
||||||
foreach ($chaptersByNumber as $chapterNumber => $chapter) {
|
foreach ($chaptersByNumber as $chapterNumber => $chapter) {
|
||||||
if (!isset($existingChapters[(float) $chapterNumber])) {
|
if (!isset($existingChapters[(float) $chapterNumber])) {
|
||||||
$manga->addChapter($chapter);
|
$manga->addChapter($chapter);
|
||||||
$newChapterIds[] = $chapter->getNumber();
|
$newChapterIds[] = $chapter->getId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ class InMemoryChapterSynchronizationService implements ChapterSynchronizationSer
|
|||||||
'synchronized_at' => new \DateTimeImmutable(),
|
'synchronized_at' => new \DateTimeImmutable(),
|
||||||
];
|
];
|
||||||
|
|
||||||
// Retourne les numéros des chapitres synchronisés (simulation)
|
// Retourne les IDs des chapitres synchronisés (simulation)
|
||||||
return [1.0, 2.0];
|
return ['chapter-1', 'chapter-2'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user