This commit is contained in:
@@ -9,11 +9,25 @@ namespace AyaNova.Biz
|
||||
{
|
||||
NotSet = 0,
|
||||
TestWidgetJob = 1,//test job for unit testing
|
||||
CoreJobSweeper = 2,
|
||||
CoreJobSweeper = 2,
|
||||
SeedTestData = 4,
|
||||
BulkCoreBizObjectOperation = 5
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SubTypes for jobs that have further distinctions
|
||||
/// </summary>
|
||||
public enum JobSubType : int
|
||||
{
|
||||
NotSet = 0,
|
||||
TagAdd = 1,
|
||||
TagAddAny = 2,
|
||||
TagRemove = 4,
|
||||
TagRemoveAny = 5,
|
||||
TagReplace = 6,
|
||||
TagReplaceAny = 7
|
||||
|
||||
}
|
||||
|
||||
}//eons
|
||||
@@ -396,8 +396,11 @@ namespace AyaNova.Biz
|
||||
/// <returns></returns>
|
||||
internal static async Task ProcessJobAsync(OpsJob job, AyContext ct)
|
||||
{
|
||||
var JobDescription = $"{job.Name} {job.JobType.ToString()}";
|
||||
if (job.SubType!=JobSubType.NotSet)
|
||||
JobDescription += $":{job.SubType}";
|
||||
|
||||
log.LogDebug($"ProcessJobAsync -> Processing job {job.Name} (type {job.JobType.ToString()})");
|
||||
log.LogDebug($"ProcessJobAsync -> Processing job {JobDescription}");
|
||||
IJobObject o = null;
|
||||
|
||||
switch (job.JobType)
|
||||
@@ -408,7 +411,9 @@ namespace AyaNova.Biz
|
||||
case JobType.SeedTestData:
|
||||
o = (IJobObject)BizObjectFactory.GetBizObject(AyaType.TrialSeeder, ct);
|
||||
break;
|
||||
case JobType.BulkCoreBizObjectOperation:
|
||||
case JobType.BulkCoreBizObjectOperation:
|
||||
//bulk op, hand off to biz object to deal with
|
||||
//note, convention is that there is an idList in job.jobinfo json if preselected else it's all objects of type
|
||||
o = (IJobObject)BizObjectFactory.GetBizObject(job.ObjectType, ct);
|
||||
break;
|
||||
default:
|
||||
@@ -416,7 +421,7 @@ namespace AyaNova.Biz
|
||||
}
|
||||
|
||||
await o.HandleJobAsync(job);
|
||||
log.LogDebug($"ProcessJobAsync -> Job completed {job.Name} (type {job.JobType.ToString()})");
|
||||
log.LogDebug($"ProcessJobAsync -> Job completed {JobDescription}");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ using EnumsNET;
|
||||
using AyaNova.Util;
|
||||
using AyaNova.Api.ControllerHelpers;
|
||||
using AyaNova.Models;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AyaNova.Biz
|
||||
{
|
||||
@@ -42,7 +44,7 @@ namespace AyaNova.Biz
|
||||
if (HasErrors)
|
||||
return null;
|
||||
else
|
||||
{
|
||||
{
|
||||
newObject.Tags = TagBiz.NormalizeTags(newObject.Tags);
|
||||
newObject.CustomFields = JsonUtil.CompactJson(newObject.CustomFields);
|
||||
await ct.Widget.AddAsync(newObject);
|
||||
@@ -173,7 +175,7 @@ namespace AyaNova.Biz
|
||||
//RESTART SERIAL
|
||||
//
|
||||
internal async Task<bool> RestartSerial(long newSerial)
|
||||
{
|
||||
{
|
||||
using (var command = ct.Database.GetDbConnection().CreateCommand())
|
||||
{
|
||||
command.CommandText = $"alter table awidget alter column serial restart with {newSerial}";
|
||||
@@ -286,6 +288,9 @@ namespace AyaNova.Biz
|
||||
//basically any error condition during job processing should throw up an exception if it can't be handled
|
||||
switch (job.JobType)
|
||||
{
|
||||
case JobType.BulkCoreBizObjectOperation:
|
||||
await ProcessBulkJobAsync(job);
|
||||
break;
|
||||
case JobType.TestWidgetJob:
|
||||
await ProcessTestJobAsync(job);
|
||||
break;
|
||||
@@ -304,18 +309,50 @@ namespace AyaNova.Biz
|
||||
var sleepTime = 30 * 1000;
|
||||
//Simulate a long running job here
|
||||
await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Running, ct);
|
||||
await JobsBiz.LogJobAsync(job.GId, $"WidgetBiz::ProcessTestJob started, sleeping for {sleepTime} seconds...", ct);
|
||||
await JobsBiz.LogJobAsync(job.GId, $"Widget ProcessTestJob started, sleeping for {sleepTime} seconds...", ct);
|
||||
//Uncomment this to test if the job prevents other routes from running
|
||||
//result is NO it doesn't prevent other requests, so we are a-ok for now
|
||||
await Task.Delay(sleepTime);
|
||||
await JobsBiz.LogJobAsync(job.GId, "WidgetBiz::ProcessTestJob done sleeping setting job to finished", ct);
|
||||
await JobsBiz.LogJobAsync(job.GId, "Widget ProcessTestJob done sleeping setting job to finished", ct);
|
||||
await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Completed, ct);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Other job handlers here...
|
||||
|
||||
private async Task ProcessBulkJobAsync(OpsJob job)
|
||||
{
|
||||
|
||||
//Simulate a long running job here
|
||||
await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Running, ct);
|
||||
await JobsBiz.LogJobAsync(job.GId, $"Widget BulkJob {job.SubType} started...", ct);
|
||||
|
||||
List<long> idList = new List<long>();
|
||||
|
||||
JObject jobData = JObject.Parse(job.JobInfo);
|
||||
if (jobData.ContainsKey("idList"))
|
||||
{
|
||||
idList = jobData["idList"].Value<List<long>>();
|
||||
}
|
||||
else{
|
||||
//we need to fetch a list of them all because ALL items was selected
|
||||
}
|
||||
var seedLevel = (Seeder.SeedLevel)jobData["seedLevel"].Value<int>();
|
||||
var timeZoneOffset = jobData["timeZoneOffset"].Value<decimal>();
|
||||
|
||||
//either process an id list or fetch all objects and process
|
||||
|
||||
//call out processor for each item in turn
|
||||
switch (job.SubType)
|
||||
{
|
||||
case JobSubType.TagAdd:
|
||||
}
|
||||
|
||||
await JobsBiz.LogJobAsync(job.GId, $"Widget BulkJob {job.SubType} completed", ct);
|
||||
await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Completed, ct);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user