case 4556
This commit is contained in:
@@ -11,7 +11,7 @@ using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace AyaNova.Biz
|
||||
{
|
||||
internal class CustomerNoteBiz : BizObject, ISearchAbleObject, IReportAbleObject, IExportAbleObject, INotifiableObject
|
||||
internal class CustomerNoteBiz : BizObject, IJobObject, ISearchAbleObject, IReportAbleObject, IExportAbleObject, INotifiableObject
|
||||
{
|
||||
internal CustomerNoteBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles UserRoles)
|
||||
{
|
||||
@@ -290,6 +290,118 @@ namespace AyaNova.Biz
|
||||
//JOB / OPERATIONS
|
||||
//
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//JOB / OPERATIONS
|
||||
//
|
||||
public async Task HandleJobAsync(OpsJob job)
|
||||
{
|
||||
//Hand off the particular job to the corresponding processing code
|
||||
//NOTE: If this code throws an exception the caller (JobsBiz::ProcessJobsAsync) will automatically set the job to failed and log the exeption so
|
||||
//basically any error condition during job processing should throw up an exception if it can't be handled
|
||||
switch (job.JobType)
|
||||
{
|
||||
case JobType.BatchCoreObjectOperation:
|
||||
await ProcessBatchJobAsync(job);
|
||||
break;
|
||||
default:
|
||||
throw new System.ArgumentOutOfRangeException($"CustomerBiz.HandleJob-> Invalid job type{job.JobType.ToString()}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private async Task ProcessBatchJobAsync(OpsJob job)
|
||||
{
|
||||
await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Running);
|
||||
await JobsBiz.LogJobAsync(job.GId, $"LT:StartJob {job.SubType}");
|
||||
List<long> idList = new List<long>();
|
||||
long FailedObjectCount = 0;
|
||||
JObject jobData = JObject.Parse(job.JobInfo);
|
||||
if (jobData.ContainsKey("idList"))
|
||||
idList = ((JArray)jobData["idList"]).ToObject<List<long>>();
|
||||
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
|
||||
{
|
||||
//--------------------------------
|
||||
//case 4192
|
||||
//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;
|
||||
LastProgressCheck = DateTime.UtcNow;
|
||||
}
|
||||
//---------------------------------
|
||||
|
||||
SaveIt = false;
|
||||
ClearErrors();
|
||||
CustomerNote o = null;
|
||||
switch (job.SubType)
|
||||
{
|
||||
case JobSubType.TagAddAny:
|
||||
case JobSubType.TagAdd:
|
||||
case JobSubType.TagRemoveAny:
|
||||
case JobSubType.TagRemove:
|
||||
case JobSubType.TagReplaceAny:
|
||||
case JobSubType.TagReplace:
|
||||
o = await GetAsync(id, false);
|
||||
SaveIt = TagBiz.ProcessBatchTagOperation(o.Tags, (string)jobData["tag"], jobData.ContainsKey("toTag") ? (string)jobData["toTag"] : null, job.SubType);
|
||||
break;
|
||||
case JobSubType.Delete:
|
||||
if (!await DeleteAsync(id))
|
||||
{
|
||||
await JobsBiz.LogJobAsync(job.GId, $"LT:Errors {GetErrorsAsString()} id {id}");
|
||||
FailedObjectCount++;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new System.ArgumentOutOfRangeException($"ProcessBatchJobAsync -> Invalid job Subtype{job.SubType}");
|
||||
}
|
||||
if (SaveIt)
|
||||
{
|
||||
o = await PutAsync(o);
|
||||
if (o == null)
|
||||
{
|
||||
await JobsBiz.LogJobAsync(job.GId, $"LT:Errors {GetErrorsAsString()} id {id}");
|
||||
FailedObjectCount++;
|
||||
}
|
||||
}
|
||||
|
||||
//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);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await JobsBiz.LogJobAsync(job.GId, $"LT:Errors id({id})");
|
||||
await JobsBiz.LogJobAsync(job.GId, ExceptionUtil.ExtractAllExceptionMessages(ex));
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------
|
||||
//case 4192
|
||||
await JobsBiz.UpdateJobProgressAsync(job.GId, $"{++CurrentRecord}/{TotalRecords}");
|
||||
//---------------------------------
|
||||
|
||||
await JobsBiz.LogJobAsync(job.GId, $"LT:BatchJob {job.SubType} {idList.Count}{(FailedObjectCount > 0 ? " - LT:Failed " + FailedObjectCount : "")}");
|
||||
await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Completed);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Other job handlers here...
|
||||
|
||||
|
||||
Reference in New Issue
Block a user