This commit is contained in:
2022-09-10 21:21:43 +00:00
parent c163311776
commit 56af1db7e7
5 changed files with 36 additions and 2 deletions

View File

@@ -202,10 +202,34 @@ namespace AyaNova.Util
return false;
}
return true;
}
///////////////////////////////////////////////
// Set global flag if db server is connectable
//
internal static void CheckDatabaseServerAvailable()
{
//Called by generator when db is down to check if it can connect
//should not run too quickly or too often so a delay is built in here
if (DateTime.UtcNow - LAST_CHECK_IF_DB_SERVER_AVAILABLE < CHECK_IF_DB_SERVER_AVAILABLE_DELAY)//no more often than every 10 seconds
return;
try
{
using (var conn = new Npgsql.NpgsqlConnection(AdminConnectionString))
{
conn.Open();
conn.Close();
}
}
catch
{
return;
}
//We have db available
ServerGlobalOpsSettingsCache.DBAVAILABLE = true;
}
private static DateTime LAST_CHECK_IF_DB_SERVER_AVAILABLE = DateTime.MinValue;
private static TimeSpan CHECK_IF_DB_SERVER_AVAILABLE_DELAY = new TimeSpan(0, 0, 10);
///////////////////////////////////////////