This commit is contained in:
@@ -596,10 +596,29 @@ namespace AyaNova.Biz
|
||||
else
|
||||
idList = await ct.Customer.AsNoTracking().Select(z => z.Id).ToListAsync();
|
||||
bool SaveIt = false;
|
||||
|
||||
//case 4192
|
||||
TimeSpan ProgressAndCancelCheckSpan = new TimeSpan(0, 0, ServerBootConfig.JOB_PROGRESS_UPDATE_AND_CANCEL_CHECK_SECONDS);
|
||||
DateTime LastProgressCheck = DateTime.UtcNow.Subtract(new TimeSpan(1, 1, 1, 1, 1));
|
||||
var TotalRecords = idList.LongCount();
|
||||
long CurrentRecord = -1;
|
||||
|
||||
|
||||
foreach (long id in idList)
|
||||
{
|
||||
try
|
||||
{
|
||||
//Update progress / cancel requested?
|
||||
CurrentRecord++;
|
||||
if (DateUtil.IsAfterDuration(LastProgressCheck, ProgressAndCancelCheckSpan))
|
||||
{
|
||||
await JobsBiz.UpdateJobProgressAsync(job.GId, $"{CurrentRecord}/{TotalRecords}");
|
||||
if (await JobsBiz.GetJobStatusAsync(job.GId) == JobStatus.CancelRequested)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SaveIt = false;
|
||||
ClearErrors();
|
||||
Customer o = null;
|
||||
@@ -635,7 +654,7 @@ namespace AyaNova.Biz
|
||||
FailedObjectCount++;
|
||||
}
|
||||
}
|
||||
//TEMPORARY MEASURE AWAITING BETTER SOLUTION AND CANCELLABLE EXTENSION JOBS
|
||||
//TEMPORARY MEASURE AWAITING BETTER SOLUTION AND CANCELLABLE EXTENSION JOBS
|
||||
//delay so we're not tying up all the resources in a tight loop
|
||||
await Task.Delay(AyaNova.Util.ServerBootConfig.JOB_OBJECT_HANDLE_BATCH_JOB_LOOP_DELAY);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,8 @@ namespace AyaNova.Biz
|
||||
Sleeping = 1,
|
||||
Running = 2,
|
||||
Completed = 3,
|
||||
Failed = 4
|
||||
Failed = 4,
|
||||
CancelRequested = 5
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -73,6 +73,16 @@ namespace AyaNova.Biz
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request the cancellation of a job, not all jobs honour this
|
||||
/// </summary>
|
||||
/// <param name="jobId"></param>
|
||||
internal static async Task RequestCancelAsync(Guid jobId)
|
||||
{
|
||||
await UpdateJobStatusAsync(jobId, JobStatus.CancelRequested);
|
||||
await LogJobAsync(jobId, "LT:Cancel");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Remove the job and it's logs
|
||||
@@ -152,6 +162,37 @@ namespace AyaNova.Biz
|
||||
return o.JobStatus;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Update the progress of a job
|
||||
/// </summary>
|
||||
/// <param name="jobId"></param>
|
||||
/// <param name="progress"></param>
|
||||
internal static async Task UpdateJobProgressAsync(Guid jobId, string progress)
|
||||
{
|
||||
using (AyContext ct = ServiceProviderProvider.DBContext)
|
||||
{
|
||||
var oFromDb = await ct.OpsJob.SingleOrDefaultAsync(z => z.GId == jobId);
|
||||
if (oFromDb == null) return;
|
||||
oFromDb.Progress = progress;
|
||||
await ct.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the progress and status of a job
|
||||
/// </summary>
|
||||
/// <param name="jobId"></param>
|
||||
internal static async Task<JobProgress> GetJobProgressAsync(Guid jobId)
|
||||
{
|
||||
using (AyContext ct = ServiceProviderProvider.DBContext)
|
||||
{
|
||||
var o = await ct.OpsJob.AsNoTracking().SingleOrDefaultAsync(z => z.GId == jobId);
|
||||
if (o == null) return new JobProgress() { JobStatus = JobStatus.Absent, Progress = string.Empty };
|
||||
return new JobProgress() { JobStatus = o.JobStatus, Progress = o.Progress };
|
||||
}
|
||||
}
|
||||
#endregion Job ops
|
||||
|
||||
#region PROCESSOR
|
||||
|
||||
Reference in New Issue
Block a user