This commit is contained in:
@@ -78,11 +78,11 @@ namespace AyaNova
|
|||||||
//parse the connection string properly
|
//parse the connection string properly
|
||||||
DbUtil.ParseConnectionString(_log, _connectionString);
|
DbUtil.ParseConnectionString(_log, _connectionString);
|
||||||
|
|
||||||
//Test for server
|
//Probe for database server
|
||||||
//Will retry 10 times every 3 seconds for a total of 30 seconds
|
//Will retry every 10 seconds for up to 5 minutes before bailing
|
||||||
if (!DbUtil.DatabaseServerExists(_log, "BOOT: waiting for db server"))
|
if (!DbUtil.DatabaseServerExists(_log, "BOOT: waiting for db server "))
|
||||||
{
|
{
|
||||||
var err = $"BOOT: E1000 - AyaNova can't connect to the database server after trying for 30 seconds (connection string is:\"{DbUtil.DisplayableConnectionString}\")";
|
var err = $"BOOT: E1000 - AyaNova can't connect to the database server after trying for 5 minutes (connection string is:\"{DbUtil.DisplayableConnectionString}\")";
|
||||||
_log.LogCritical(err);
|
_log.LogCritical(err);
|
||||||
throw new System.ApplicationException(err);
|
throw new System.ApplicationException(err);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,17 +120,18 @@ namespace AyaNova.Util
|
|||||||
|
|
||||||
///////////////////////////////////////////
|
///////////////////////////////////////////
|
||||||
//Verify that server exists
|
//Verify that server exists
|
||||||
|
// spend up to 5 minutes waiting for it to come up before bailing
|
||||||
//
|
//
|
||||||
internal static bool DatabaseServerExists(ILogger log, string logPrepend)
|
internal static bool DatabaseServerExists(ILogger log, string logPrepend)
|
||||||
{
|
{
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//Try every 3 seconds for 10 tries before giving up
|
//Try every 10 seconds for 30 tries before giving up (5 minutes total)
|
||||||
|
|
||||||
var maxRetryAttempts = 10;
|
var maxRetryAttempts = 30;
|
||||||
var pauseBetweenFailures = TimeSpan.FromSeconds(3);
|
var pauseBetweenFailures = TimeSpan.FromSeconds(10);
|
||||||
RetryHelper.RetryOnException(maxRetryAttempts, pauseBetweenFailures, log, logPrepend + AdminConnectionString, () =>
|
RetryHelper.RetryOnException(maxRetryAttempts, pauseBetweenFailures, log, logPrepend + DisplayableConnectionString, () =>
|
||||||
{
|
{
|
||||||
using (var conn = new Npgsql.NpgsqlConnection(AdminConnectionString))
|
using (var conn = new Npgsql.NpgsqlConnection(AdminConnectionString))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ namespace AyaNova.Util
|
|||||||
if (attempts == times)
|
if (attempts == times)
|
||||||
throw;
|
throw;
|
||||||
|
|
||||||
log.LogError(ex, $"{logPrepend} Exception caught on attempt {attempts} - will retry after delay {delay}");
|
log.LogError(ex, $"{logPrepend} Exception caught on attempt {attempts} of {times} - will retry after delay {delay}");
|
||||||
|
|
||||||
Task.Delay(delay).Wait();
|
Task.Delay(delay).Wait();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user