1
0
Fork 0
mirror of synced 2024-06-29 19:50:26 +12:00

Merge pull request #2423 from appwrite/fix-usage-worker-influxdb-check

fix(usage): influxdb health check
This commit is contained in:
Torsten Dittmann 2021-11-23 17:03:19 +01:00 committed by GitHub
commit 8e09a7eb9c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -246,17 +246,19 @@ $cli
$max = 10; $max = 10;
$sleep = 1; $sleep = 1;
$database = $client->selectDB('telegraf');
do { // check if telegraf database is ready do { // check if telegraf database is ready
$attempts++; try {
if(!in_array('telegraf', $client->listDatabases())) { $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})..."); Console::warning("InfluxDB not ready. Retrying connection ({$attempts})...");
if($attempts >= $max) { if($attempts >= $max) {
throw new \Exception('InfluxDB database not ready yet'); throw new \Exception('InfluxDB database not ready yet');
} }
sleep($sleep); sleep($sleep);
} else {
break; // leave the do-while if successful
} }
} while ($attempts < $max); } while ($attempts < $max);
@ -382,7 +384,7 @@ $cli
$dbForProject->updateDocument('stats', $document->getId(), $dbForProject->updateDocument('stats', $document->getId(),
$document->setAttribute('value', $storageTotal)); $document->setAttribute('value', $storageTotal));
} }
$time = (int) (floor(time() / 86400) * 86400); // Time rounded to nearest day $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 $id = \md5($time . '_1d_storage.total'); //Construct unique id for each metric using time, period and metric
$document = $dbForProject->getDocument('stats', $id); $document = $dbForProject->getDocument('stats', $id);