This commit is contained in:
2020-05-25 22:22:34 +00:00
parent a27066bbfd
commit a10a3e3069
4 changed files with 45 additions and 29 deletions

View File

@@ -19,6 +19,7 @@ namespace AyaNova.Biz
{
private static ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger("CoreJobBackup");
private static bool BackupIsRunning = false;
private const int MAXIMUM_MS_ALLOWED_FOR_PROCESSING = 15 * 60 * 1000;//wild assed guess 15 minutes maximum to run backup command, ever
////////////////////////////////////////////////////////////////////////////////////////////////
//
//
@@ -26,18 +27,18 @@ namespace AyaNova.Biz
{
//## TEST TEMPORARY
//This should trigger the kill switch for generator
System.Diagnostics.Debug.WriteLine($"CoreJobBackup test wait 5 minutes starting now...");
await Task.Delay(new TimeSpan(0,5,0));
System.Diagnostics.Debug.WriteLine($"CoreJobBackup test wait 2 minutes starting now...");
await Task.Delay(new TimeSpan(0, 2, 0));
if (BackupIsRunning) return;
if (!OnDemand)
{
log.LogTrace("Checking if backup should run");
log.LogTrace("Checking if backup should run");
if (DateTime.UtcNow < ServerGlobalOpsSettingsCache.NextBackup)
{
log.LogTrace("Not past backup time yet");
log.LogTrace("Not past backup time yet");
return;
}
}
}
AyaNova.Api.ControllerHelpers.ApiServerState apiServerState = null;
try
@@ -48,7 +49,7 @@ namespace AyaNova.Biz
apiServerState.SetClosed("BACKUP RUNNING");
await JobsBiz.LogJobAsync(Guid.Empty, $"Starting backup job {(OnDemand ? "manual / on demand" : "scheduled") } ");
log.LogDebug("Backup starting");
var DemandFileNamePrepend=OnDemand?"manual-":string.Empty;
var DemandFileNamePrepend = OnDemand ? "manual-" : string.Empty;
//*************
//DO DATA BACKUP
//build command
@@ -68,16 +69,16 @@ namespace AyaNova.Biz
var Arguments = $"{DBNameParameter} -Fc > {DataBackupFile}";
var Result = RunProgram.Run(BackupUtilityCommand, Arguments, log);
var Result = RunProgram.Run(BackupUtilityCommand, Arguments, log, MAXIMUM_MS_ALLOWED_FOR_PROCESSING);
if (string.IsNullOrWhiteSpace(Result))
{
log.LogDebug("BACKUP SUCCESSFUL (NO ERROR)");
}
else
{
await JobsBiz.LogJobAsync(Guid.Empty, $"Error during data backup \"{Result}\"");
log.LogError($"BACKUP ERROR: {Result}");
//TODO:OPSNOTIFY
}
//DO FILE BACKUP IF ATTACHMENTS BACKED UP
@@ -100,12 +101,13 @@ namespace AyaNova.Biz
await JobsBiz.LogJobAsync(Guid.Empty, "Backup failed with errors:");
await JobsBiz.LogJobAsync(Guid.Empty, ExceptionUtil.ExtractAllExceptionMessages(ex));
log.LogError(ex, "Backup failed");
//TODO:OPSNOTIFY
throw ex;
}
finally
{
//bump the backup date if automatic backup
if(!OnDemand)
if (!OnDemand)
ServerGlobalOpsSettingsCache.SetNextBackup();
apiServerState.ResumePriorState();
BackupIsRunning = false;

View File

@@ -2,8 +2,6 @@ using System.Threading;
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.DependencyInjection;
using AyaNova.Models;
using AyaNova.Api.ControllerHelpers;
using AyaNova.Biz;
using AyaNova.Util;