diff --git a/docker-compose.override.yaml b/docker-compose.override.yaml index 25b996d..0fea8d9 100644 --- a/docker-compose.override.yaml +++ b/docker-compose.override.yaml @@ -11,6 +11,11 @@ services: ports: - "${PORT_80:-80}:80" + messenger: + command: ["php", "-d", "memory_limit=512M", "bin/console", "messenger:consume", "async", "--time-limit=3600", "--memory-limit=256M", "-vv", "--no-debug"] + volumes: + - .:/app + database: ports: - "0.0.0.0:5432:5432" diff --git a/src/MessageHandler/ImportFilmsBatchMessageHandler.php b/src/MessageHandler/ImportFilmsBatchMessageHandler.php index 43928a8..fe57eb5 100644 --- a/src/MessageHandler/ImportFilmsBatchMessageHandler.php +++ b/src/MessageHandler/ImportFilmsBatchMessageHandler.php @@ -5,9 +5,7 @@ declare(strict_types=1); namespace App\MessageHandler; use App\Entity\Import; -use App\Entity\Notification; use App\Entity\UserMovie; -use App\Exception\GatewayException; use App\Gateway\LtbxdGateway; use App\Message\ImportFilmsBatchMessage; use App\Repository\ImportRepository; @@ -51,7 +49,8 @@ readonly class ImportFilmsBatchMessageHandler } $batch = array_slice($ltbxdMovies, $message->offset, $message->limit); - $user = $import->getUser(); + $userId = $import->getUser()->getId(); + $importId = $import->getId(); foreach ($batch as $ltbxdMovie) { try { @@ -63,6 +62,7 @@ readonly class ImportFilmsBatchMessageHandler $this->actorSyncer->syncActorsForMovie($movie); + $user = $this->em->getReference(\App\Entity\User::class, $userId); $existingLink = $this->em->getRepository(UserMovie::class)->findOneBy([ 'user' => $user, 'movie' => $movie, @@ -78,11 +78,14 @@ readonly class ImportFilmsBatchMessageHandler } catch (\Throwable $e) { $this->logger->warning('Failed to import film', [ 'film' => $ltbxdMovie->getName(), - 'importId' => $import->getId(), + 'importId' => $importId, 'error' => $e->getMessage(), ]); $this->importRepository->incrementFailedFilms($import); } + + $this->em->clear(); + $import = $this->em->getRepository(Import::class)->find($importId); } $processedBatches = $this->importRepository->incrementProcessedBatches($import); @@ -94,17 +97,6 @@ readonly class ImportFilmsBatchMessageHandler $import->setStatus(Import::STATUS_COMPLETED); $import->setCompletedAt(new \DateTimeImmutable()); $this->em->flush(); - - $imported = $import->getTotalFilms() - $import->getFailedFilms(); - $notification = new Notification(); - $notification->setUser($user); - $notification->setMessage(sprintf( - 'Import terminé : %d/%d films importés.', - $imported, - $import->getTotalFilms() - )); - $this->em->persist($notification); - $this->em->flush(); } } } diff --git a/src/MessageHandler/ProcessImportMessageHandler.php b/src/MessageHandler/ProcessImportMessageHandler.php index 063bcd3..5fbd56a 100644 --- a/src/MessageHandler/ProcessImportMessageHandler.php +++ b/src/MessageHandler/ProcessImportMessageHandler.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace App\MessageHandler; use App\Entity\Import; -use App\Entity\Notification; use App\Gateway\LtbxdGateway; use App\Message\ImportFilmsBatchMessage; use App\Message\ProcessImportMessage; @@ -72,12 +71,6 @@ readonly class ProcessImportMessageHandler $import->setStatus(Import::STATUS_FAILED); $this->em->flush(); - - $notification = new Notification(); - $notification->setUser($import->getUser()); - $notification->setMessage('L\'import a échoué.'); - $this->em->persist($notification); - $this->em->flush(); } } }