feat: finalizing Scraping endpoint

This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2025-02-10 17:28:49 +01:00
parent 0374ab0e46
commit 073439163b
28 changed files with 447 additions and 86 deletions

View File

@@ -5,9 +5,11 @@ namespace App\Domain\Scraping\Application\CommandHandler;
use App\Domain\Scraping\Application\Command\ScrapeChapter;
use App\Domain\Scraping\Domain\Contract\Repository\ScrapingJobRepositoryInterface;
use App\Domain\Scraping\Domain\Contract\Service\ScraperInterface;
use App\Domain\Scraping\Domain\Event\ChapterScraped;
use App\Domain\Scraping\Domain\Event\ChapterScrapingFailed;
use App\Domain\Scraping\Domain\Event\ChapterScrapingStarted;
use App\Domain\Scraping\Domain\Model\ScrapingJob;
use App\Domain\Scraping\Domain\Model\ScrapingStatus;
use Ramsey\Uuid\Uuid;
use Symfony\Component\Messenger\MessageBusInterface;
@@ -34,7 +36,15 @@ readonly class ScrapeChapterHandler
$this->eventBus->dispatch(new ChapterScrapingStarted($job->getId()));
$this->scraper->scrape($job);
$job = $this->scraper->scrape($job);
if($job->status === ScrapingStatus::FAILED) {
$this->eventBus->dispatch(new ChapterScrapingFailed($command->mangaId, $command->chapterNumber, $job->failureReason));
}elseif ($job->status === ScrapingStatus::COMPLETED) {
$this->eventBus->dispatch(new ChapterScraped($job->getId()));
}
$this->scrapingJobRepository->save($job);
} catch (\Exception $e) {
$this->eventBus->dispatch(new ChapterScrapingFailed($command->mangaId, $command->chapterNumber, $e->getMessage()));
throw $e;