Merge branch 'main' into feat/monitoring-run-command

This commit is contained in:
2026-03-27 14:23:21 +01:00
5 changed files with 226 additions and 5 deletions

View File

@@ -20,7 +20,7 @@ readonly class CheckMonitoredMangasHandler
{
$criteria = new MonitoringCriteria(
enabled: true,
lastCheckBefore: $command->since ?? new \DateTimeImmutable('-1 hour')
lastCheckBefore: new \DateTimeImmutable('-2 hours')
);
$monitoredMangas = $this->mangaRepository->findByMonitoringCriteria($criteria);

View File

@@ -21,9 +21,7 @@ class MonitoringSchedule implements ScheduleProviderInterface
{
return (new Schedule())->add(
// Toutes les 2 heures, vérifie les mangas qui n'ont pas été vérifiés depuis 2 heures
RecurringMessage::every('2 hours', new CheckMonitoredMangas(
new \DateTimeImmutable('-2 hours')
))
RecurringMessage::every('2 hours', new CheckMonitoredMangas())
)->stateful($this->cache);
}
}

View File

@@ -7,6 +7,9 @@ use App\Domain\Scraping\Application\Command\ScrapeChapter;
use App\Domain\Scraping\Application\CommandHandler\ScrapeChapterHandler;
use App\Domain\Scraping\Domain\Contract\Repository\ChapterRepositoryInterface;
use App\Domain\Scraping\Domain\Contract\Repository\MangaRepositoryInterface;
use App\Domain\Scraping\Domain\Model\ScrapingJob;
use App\Domain\Shared\Domain\Contract\JobRepositoryInterface;
use Ramsey\Uuid\Uuid;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
class AutoScrapingListener
@@ -15,6 +18,7 @@ class AutoScrapingListener
private readonly ScrapeChapterHandler $scrapeChapterHandler,
private readonly ChapterRepositoryInterface $chapterRepository,
private readonly MangaRepositoryInterface $mangaRepository,
private readonly JobRepositoryInterface $jobRepository,
) {
}
@@ -25,7 +29,12 @@ class AutoScrapingListener
$manga = $this->mangaRepository->getById($chapter->mangaId);
if ($manga->isMonitored()) {
$this->scrapeChapterHandler->handle(new ScrapeChapter($event->chapterId->getValue()));
$jobId = Uuid::uuid4()->toString();
$job = new ScrapingJob($jobId);
$job->context['chapterId'] = $event->chapterId->getValue();
$this->jobRepository->save($job);
$this->scrapeChapterHandler->handle(new ScrapeChapter($event->chapterId->getValue(), $jobId));
}
}
}