This commit is contained in:
2020-05-19 19:15:56 +00:00
parent 418667303a
commit b38b3a6568
3 changed files with 33 additions and 15 deletions

View File

@@ -141,7 +141,7 @@ namespace AyaNova.Biz
/// <param name="ct"></param>
/// <returns></returns>
internal static async Task<OpsJob> AddJobAsync(OpsJob newJob, AyContext ct)
{
{
await ct.OpsJob.AddAsync(newJob);
await ct.SaveChangesAsync();
return newJob;
@@ -372,6 +372,9 @@ namespace AyaNova.Biz
return;
}
//backup
await CoreJobBackup.DoWorkAsync(ct);
//Notifications
}
@@ -396,7 +399,7 @@ namespace AyaNova.Biz
internal static async Task ProcessJobAsync(OpsJob job, AyContext ct)
{
var JobDescription = $"{job.Name} {job.JobType.ToString()}";
if (job.SubType!=JobSubType.NotSet)
if (job.SubType != JobSubType.NotSet)
JobDescription += $":{job.SubType}";
log.LogDebug($"ProcessJobAsync -> Processing job {JobDescription}");

View File

@@ -24,37 +24,50 @@ namespace AyaNova.Biz
//
public static async Task DoWorkAsync(AyContext ct)
{
if (BackupIsRunning) return;
//get NOW in utc
DateTime utcNow = DateTime.UtcNow;
//what time should we backup today?
DateTime todayBackupTime = new DateTime(utcNow.Year, utcNow.Month, utcNow.Day, ServerGlobalOpsSettings.BackupTime.Hour, ServerGlobalOpsSettings.BackupTime.Minute, 0, DateTimeKind.Utc);//first start with NOW
//Are we there yet?
if (utcNow < todayBackupTime) return;//nope
//Yes, we've passed into the backup window time, but that's also true if we just ran the backup as well so
//need to check for that as well...
//Has last backup run more than 24 hours ago?
if (ServerGlobalOpsSettings.LastBackup > utcNow.AddHours(-24))
return;//nope, so we have already run today's backup
//Ok, we're into backup time and it's been more than 24 hours since it last ran so let's do this...
BackupIsRunning = true;
log.LogTrace("Backup starting");
try
{
BackupIsRunning = true;
log.LogTrace("Backup starting");
//*************
//*************
log.LogInformation("SIMULATED BACKUP RUNNING NOW - TORA TORA TORA!");
//***************
//BACKUP TORA TORA TORA!
//***************
//Update last backup
var biz = GlobalOpsSettingsBiz.GetBiz(ct);
var OpSet = await biz.GetAsync(false);
OpSet.LastBackup = utcNow;
await biz.ReplaceAsync(OpSet);
//Update last backup
BackupIsRunning = false;
log.LogTrace("Backup completed");
log.LogTrace("Backup completed");
}
catch (Exception ex)
{
log.LogError(ex, "BACKUP FAILED!");
throw ex;
}
finally
{
BackupIsRunning = false;
}
}

View File

@@ -15,7 +15,9 @@ namespace AyaNova.Models
public GlobalOpsSettings()
{
Id = 1;//always 1
BackupTime = new DateTime(2020, 5, 19, 23, 59, 0, DateTimeKind.Utc);//date doesn't matter it only uses hour
// BackupTime = new DateTime(2020, 5, 19, 23, 59, 0, DateTimeKind.Utc);//date doesn't matter it only uses hour
//testing only, above is the correct one
BackupTime = DateTime.UtcNow.AddMinutes(1);
LastBackup = DateTime.MinValue;
BackupSetsToKeep = 3;