From efc1cc9a45160f3c6f29a03c908db33ec3958763 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gangloff?= Date: Mon, 23 Dec 2024 15:22:54 +0100 Subject: [PATCH] fix: avoid sending error notifications if the problem is with the InfluxDB server --- src/Service/InfluxdbService.php | 14 +++++++++----- src/Service/StatService.php | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Service/InfluxdbService.php b/src/Service/InfluxdbService.php index c031de4..855ba42 100644 --- a/src/Service/InfluxdbService.php +++ b/src/Service/InfluxdbService.php @@ -79,11 +79,15 @@ readonly class InfluxdbService private function writePoints(Point ...$points): void { - $writeApi = $this->client->createWriteApi(['writeType' => WriteType::BATCHING, 'batchSize' => count($points)]); - foreach ($points as $point) { - $writeApi->write($point); - } + try { + $writeApi = $this->client->createWriteApi(['writeType' => WriteType::BATCHING, 'batchSize' => count($points)]); + foreach ($points as $point) { + $writeApi->write($point); + } - $writeApi->close(); + $writeApi->close(); + } catch (\Throwable) { + // TODO: Add a retry mechanism if writing fails + } } } diff --git a/src/Service/StatService.php b/src/Service/StatService.php index f1718b8..efd36c2 100644 --- a/src/Service/StatService.php +++ b/src/Service/StatService.php @@ -19,6 +19,7 @@ readonly class StatService return $this->pool->save($item); } catch (\Throwable) { + // TODO: Add a retry mechanism if writing fails } return false;