1
0
Fork 0
mirror of synced 2024-06-01 18:39:57 +12:00

Define loop control vars outside loop

This commit is contained in:
kodumbeats 2021-07-20 15:11:54 -04:00
parent e16bfe7fd3
commit 12e2ebc2b5

View file

@ -56,6 +56,9 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) {
go(function() use ($register, $app) {
// wait for database to be ready
$attempts = 0;
$max = 10;
$sleep = 1;
do {
try {
$attempts++;
@ -64,13 +67,13 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) {
break; // leave the do-while if successful
} catch(\Exception $e) {
Console::warning("Database not ready. Retrying connection ({$attempts})...");
if ($attempts >= 10) {
if ($attempts >= $max) {
throw new \Exception('Failed to connect to database: '. $e->getMessage());
}
sleep(1);
sleep($sleep);
continue;
}
} while ($attempts < 10);
} while ($attempts < $max);
App::setResource('db', function () use (&$db) {
return $db;