This commit is contained in:
2022-09-10 22:41:40 +00:00
parent 4c9fc68ef7
commit 203346e808

View File

@@ -210,26 +210,33 @@ namespace AyaNova.Util
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
if (CHECKING_DB_AVAILABLE) return;
//don't check too often just fills log files for no reason
if (DateTime.UtcNow - CHECKED_DB_AVAILABLE_LAST < CHECK_DB_AVAILABLE_EVERY_INTERVAL)
return;
CHECKING_DB_AVAILABLE = true;
try
{
using (var conn = new Npgsql.NpgsqlConnection(AdminConnectionString))
using (AyContext ct = ServiceProviderProvider.DBContext)
{
conn.Open();
conn.Close();
var dummy = ct.GlobalBizSettings.FirstOrDefault(z => z.Id == 1);
}
}
catch
{
return;
}
finally
{
CHECKED_DB_AVAILABLE_LAST = DateTime.UtcNow;
CHECKING_DB_AVAILABLE = false;
}
//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);
private static bool CHECKING_DB_AVAILABLE = false;
private static DateTime CHECKED_DB_AVAILABLE_LAST = DateTime.MinValue;
private static TimeSpan CHECK_DB_AVAILABLE_EVERY_INTERVAL = new TimeSpan(0, 0, 60);
///////////////////////////////////////////////////////////
@@ -242,7 +249,7 @@ namespace AyaNova.Util
if (ex.Message.Contains("transient failure") && ex.Source.Contains("PostgreSQL"))
ServerGlobalOpsSettingsCache.DBAVAILABLE = false;
}
///////////////////////////////////////////
//Verify that database exists, if not, then create it