1
0
Fork 0
mirror of synced 2024-06-03 03:14:50 +12:00

Attempt to reconnect deletes worker to db

This commit is contained in:
kodumbeats 2021-07-20 15:13:00 -04:00
parent 12e2ebc2b5
commit 1b051d32fe

View file

@ -389,9 +389,27 @@ class DeletesV1 extends Worker
{
global $register;
$cache = new Cache(new RedisCache($register->get('cache')));
$dbForConsole = new Database(new MariaDB($register->get('db')), $cache);
$dbForConsole->setNamespace('project_console_internal'); // Main DB
// wait for database to be ready
$attempts = 0;
$max = 5;
$sleep = 5;
do {
try {
$attempts++;
$cache = new Cache(new RedisCache($register->get('cache')));
$dbForConsole = new Database(new MariaDB($register->get('db')), $cache);
$dbForConsole->setNamespace('project_console_internal'); // Main DB
break; // leave the do-while if successful
} catch(\Exception $e) {
Console::warning("Database not ready. Retrying connection ({$attempts})...");
if ($attempts >= $max) {
throw new \Exception('Failed to connect to database: '. $e->getMessage());
}
sleep($sleep);
continue;
}
} while ($attempts < $max);
return $dbForConsole;
}