From 544ba24af25a12a65cd6d6409b1f4183ea6623e7 Mon Sep 17 00:00:00 2001 From: Gwadaking Date: Thu, 9 Apr 2026 00:14:34 -0400 Subject: [PATCH] =?UTF-8?q?fix:=20alerte=20critique=20si=200=20zones=20ing?= =?UTF-8?q?=C3=A9r=C3=A9es=20+=20lastIngestionJob=20dans=20/api/status?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/Controller/StatusController.php | 24 +++++++++++++++---- .../IngestionScheduleHandler.php | 18 ++++++++++++++ 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/backend/src/Controller/StatusController.php b/backend/src/Controller/StatusController.php index 9dac2c7..7934e32 100644 --- a/backend/src/Controller/StatusController.php +++ b/backend/src/Controller/StatusController.php @@ -17,17 +17,31 @@ class StatusController extends AbstractController public function __invoke(): JsonResponse { - $row = $this->connection->fetchAssociative( + $obs = $this->connection->fetchAssociative( 'SELECT detected_at, source, coverage_area FROM sargassum_observation ORDER BY detected_at DESC LIMIT 1' ); + $job = $this->connection->fetchAssociative( + "SELECT status, source, error_message, created_at, processed_at, retry_count + FROM data_ingestion_job + ORDER BY created_at DESC LIMIT 1" + ); + return $this->json([ - 'lastObservation' => $row !== false ? [ - 'detectedAt' => $row['detected_at'], - 'source' => $row['source'], - 'coverageKm2' => $row['coverage_area'] !== null ? (float) $row['coverage_area'] : null, + 'lastObservation' => $obs !== false ? [ + 'detectedAt' => $obs['detected_at'], + 'source' => $obs['source'], + 'coverageKm2' => $obs['coverage_area'] !== null ? (float) $obs['coverage_area'] : null, + ] : null, + 'lastIngestionJob' => $job !== false ? [ + 'status' => $job['status'], + 'source' => $job['source'], + 'error' => $job['error_message'], + 'startedAt' => $job['created_at'], + 'finishedAt' => $job['processed_at'], + 'retryCount' => (int) $job['retry_count'], ] : null, ]); } diff --git a/backend/src/MessageHandler/IngestionScheduleHandler.php b/backend/src/MessageHandler/IngestionScheduleHandler.php index 1a24b37..4c610f1 100644 --- a/backend/src/MessageHandler/IngestionScheduleHandler.php +++ b/backend/src/MessageHandler/IngestionScheduleHandler.php @@ -43,15 +43,33 @@ final class IngestionScheduleHandler $this->logger->info('Scheduled ingestion started', ['date' => $date->format('Y-m-d')]); // Étape 1 : ingestion de toutes les zones + $succeeded = 0; + $failed = 0; foreach (self::ZONES as $name => $bbox) { try { $this->ingestion->ingestWithFallback($bbox, $date); $this->logger->info('Zone ingested', ['zone' => $name]); + ++$succeeded; } catch (\Throwable $e) { $this->logger->error('Ingestion failed', ['zone' => $name, 'error' => $e->getMessage()]); + ++$failed; } } + if ($succeeded === 0) { + $this->logger->critical('All zones failed — no data ingested this cycle', [ + 'date' => $date->format('Y-m-d'), + 'zones' => array_keys(self::ZONES), + 'count' => $failed, + ]); + } else { + $this->logger->info('Ingestion cycle summary', [ + 'succeeded' => $succeeded, + 'failed' => $failed, + 'date' => $date->format('Y-m-d'), + ]); + } + // Étape 2 : forecasts pour les observations sans prévision $observations = $this->em->getRepository(SargassumObservation::class) ->createQueryBuilder('o')