From 4378dfe7241c7eb8f90df463d00d0cde5b90ea70 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Thu, 18 Nov 2021 11:46:39 +0100 Subject: [PATCH] fix(usage): influxdb health check --- app/tasks/usage.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/tasks/usage.php b/app/tasks/usage.php index 701037fcc..dac8f7fe9 100644 --- a/app/tasks/usage.php +++ b/app/tasks/usage.php @@ -246,17 +246,19 @@ $cli $max = 10; $sleep = 1; - $database = $client->selectDB('telegraf'); do { // check if telegraf database is ready - $attempts++; - if(!in_array('telegraf', $client->listDatabases())) { + try { + $attempts++; + $database = $client->selectDB('telegraf'); + if(in_array('telegraf', $client->listDatabases())) { + break; // leave the do-while if successful + } + } catch (\Throwable $th) { Console::warning("InfluxDB not ready. Retrying connection ({$attempts})..."); if($attempts >= $max) { throw new \Exception('InfluxDB database not ready yet'); } sleep($sleep); - } else { - break; // leave the do-while if successful } } while ($attempts < $max); @@ -382,7 +384,7 @@ $cli $dbForProject->updateDocument('stats', $document->getId(), $document->setAttribute('value', $storageTotal)); } - + $time = (int) (floor(time() / 86400) * 86400); // Time rounded to nearest day $id = \md5($time . '_1d_storage.total'); //Construct unique id for each metric using time, period and metric $document = $dbForProject->getDocument('stats', $id);