feat(Core/DB): reconnect seconds and attempts configurable (#5673)

This commit is contained in:
Francesco Borzì
2021-05-10 20:09:23 +02:00
committed by GitHub
parent ebd757a331
commit 053f9f5fa4
3 changed files with 31 additions and 15 deletions

View File

@@ -39,26 +39,18 @@ DatabaseLoader& DatabaseLoader::AddDatabase(DatabaseWorkerPool<T>& pool, std::st
// Try reconnect
if (error == CR_CONNECTION_ERROR)
{
// Possible improvement for future: make ATTEMPTS and SECONDS configurable values
uint32 const ATTEMPTS = 5;
Seconds durationSecs = 5s;
uint32 count = 1;
uint8 const ATTEMPTS = sConfigMgr->GetOption<uint8>("Database.Reconnect.Attempts", 20);
Seconds RECONNECT_SECONDS = Seconds(sConfigMgr->GetOption<uint8>("Database.Reconnect.Seconds", 15));
uint8 count = 0;
auto sleepThread = [&]()
{
LOG_INFO("sql.driver", "> Retrying after %u seconds", static_cast<uint32>(durationSecs.count()));
std::this_thread::sleep_for(durationSecs);
};
sleepThread();
do
while (count < ATTEMPTS)
{
LOG_INFO("sql.driver", "> Retrying after %u seconds", static_cast<uint32>(RECONNECT_SECONDS.count()));
std::this_thread::sleep_for(RECONNECT_SECONDS);
error = pool.Open();
if (error == CR_CONNECTION_ERROR)
{
sleepThread();
count++;
}
else
@@ -66,7 +58,7 @@ DatabaseLoader& DatabaseLoader::AddDatabase(DatabaseWorkerPool<T>& pool, std::st
break;
}
} while (count < ATTEMPTS);
}
}
// If the error wasn't handled quit