This commit is contained in:
2020-05-19 19:24:56 +00:00
parent c9fa5b55aa
commit aa6dfe5fe8

View File

@@ -1,7 +1,5 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using AyaNova.Models;
using AyaNova.Util;
@@ -53,14 +51,15 @@ namespace AyaNova.Biz
//*************
//DO DATA BACKUP
log.LogInformation("SIMULATED BACKUP RUNNING NOW - TORA TORA TORA!");
log.LogInformation("BACKUP STUB: DATA BACKUP RUNNING NOW - TORA TORA TORA!");
log.LogInformation($"dbdump path: {ServerBootConfig.AYANOVA_BACKUP_PG_DUMP_PATH}");
//DO FILE BACKUP IF ATTACHMENTS BACKED UP
//OPNE SERVER
log.LogInformation("BACKUP STUB: ATTACHMENTS BACKUP RUNNING NOW");
//PRUNE BACKUP SETS NOT KEPT
log.LogInformation("BACKUP STUB: PRUNING RUNNING NOW");
//v.next - COPY TO ONLINE STORAGE
@@ -87,60 +86,6 @@ namespace AyaNova.Biz
}
private static async Task sweepAsync(AyContext ct, DateTime dtDeleteCutoff, JobStatus jobStatus)
{
//Get the deleteable succeeded jobs list
var jobs = await ct.OpsJob
.AsNoTracking()
.Where(z => z.Created < dtDeleteCutoff && z.JobStatus == jobStatus)
.OrderBy(z => z.Created)
.ToListAsync();
log.LogTrace($"SweepAsync processing: cutoff={dtDeleteCutoff.ToString()}, for {jobs.Count.ToString()} jobs of status {jobStatus.ToString()}");
foreach (OpsJob j in jobs)
{
try
{
await JobsBiz.DeleteJobAndLogAsync(j.GId, ct);
}
catch (Exception ex)
{
log.LogError(ex, "sweepAsync exception calling JobsBiz.DeleteJobAndLogAsync");
//for now just throw it but this needs to be removed when logging added and better handling
throw (ex);
}
}
}
/// <summary>
/// Kill jobs that have been stuck in "running" state for too long
/// </summary>
/// <param name="ct"></param>
/// <param name="dtRunningDeadline"></param>
/// <returns></returns>
private static async Task killStuckJobsAsync(AyContext ct, DateTime dtRunningDeadline)
{
//Get the deleteable succeeded jobs list
var jobs = await ct.OpsJob
.AsNoTracking()
.Where(z => z.Created < dtRunningDeadline && z.JobStatus == JobStatus.Running)
.OrderBy(z => z.Created)
.ToListAsync();
log.LogTrace($"killStuckJobsAsync processing: cutoff={dtRunningDeadline.ToString()}, for {jobs.Count.ToString()} jobs of status {JobStatus.Running.ToString()}");
foreach (OpsJob j in jobs)
{
//OPSMETRIC
await JobsBiz.LogJobAsync(j.GId, "Job took too long to run - setting to failed", ct);
log.LogError($"Job found job stuck in running status and set to failed: deadline={dtRunningDeadline.ToString()}, jobId={j.GId.ToString()}, jobname={j.Name}, jobtype={j.JobType.ToString()}, jobObjectType={j.ObjectType.ToString()}, jobObjectId={j.ObjectId.ToString()}");
await JobsBiz.UpdateJobStatusAsync(j.GId, JobStatus.Failed, ct);
}
}
/////////////////////////////////////////////////////////////////////