fix: resolve messenger worker OOM by clearing EntityManager and disabling debug
Clear Doctrine identity map after each film import to prevent memory accumulation. Run messenger with --no-debug and higher PHP memory_limit to avoid profiling overhead in dev. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user