This commit is contained in:
@@ -134,7 +134,24 @@ namespace AyaNova.Api.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Trigger a test job that simulates a (30 second) long running operation for testing and ops confirmation
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Job id</returns>
|
||||||
|
[HttpPost("test-job")]
|
||||||
|
public async Task<IActionResult> TestWidgetJob()
|
||||||
|
{
|
||||||
|
if (!serverState.IsOpen)
|
||||||
|
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||||
|
if (!Authorized.HasModifyRole(HttpContext.Items, AyaType.ServerJob))
|
||||||
|
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||||
|
OpsJob j = new OpsJob();
|
||||||
|
j.Name = "TestJob";
|
||||||
|
j.JobType = JobType.TestJob;
|
||||||
|
await JobsBiz.AddJobAsync(j, ct);
|
||||||
|
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.ServerJob, AyaEvent.Created, $"{j.JobType} {j.Name}"), ct);
|
||||||
|
return Accepted(new { JobId = j.GId });//202 accepted
|
||||||
|
}
|
||||||
|
|
||||||
//------------
|
//------------
|
||||||
|
|
||||||
|
|||||||
@@ -212,29 +212,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get route that submits a simulated long running operation job for testing
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Nothing</returns>
|
|
||||||
[HttpGet("testwidgetjob")]
|
|
||||||
public async Task<IActionResult> TestWidgetJob()
|
|
||||||
{
|
|
||||||
if (!serverState.IsOpen)
|
|
||||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
|
||||||
|
|
||||||
if (!Authorized.HasModifyRole(HttpContext.Items, AyaType.ServerJob))
|
|
||||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
|
||||||
|
|
||||||
//Create the job here
|
|
||||||
OpsJob j = new OpsJob();
|
|
||||||
j.Name = "TestWidgetJob";
|
|
||||||
j.JobType = JobType.TestWidgetJob;
|
|
||||||
await JobsBiz.AddJobAsync(j, ct);
|
|
||||||
//Log
|
|
||||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.ServerJob, AyaEvent.Created, $"{j.JobType} {j.Name}"), ct);
|
|
||||||
|
|
||||||
return Accepted(new { JobId = j.GId });//202 accepted
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------
|
//------------
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace AyaNova.Biz
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
internal class JobOperationsBiz : BizObject
|
internal class JobOperationsBiz : BizObject, IJobObject
|
||||||
{
|
{
|
||||||
|
|
||||||
internal JobOperationsBiz(AyContext dbcontext, long currentUserId, AuthorizationRoles userRoles)
|
internal JobOperationsBiz(AyContext dbcontext, long currentUserId, AuthorizationRoles userRoles)
|
||||||
@@ -18,17 +18,14 @@ namespace AyaNova.Biz
|
|||||||
ct = dbcontext;
|
ct = dbcontext;
|
||||||
UserId = currentUserId;
|
UserId = currentUserId;
|
||||||
CurrentUserRoles = userRoles;
|
CurrentUserRoles = userRoles;
|
||||||
BizType=AyaType.ServerJob;
|
BizType = AyaType.ServerJob;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#region CONTROLLER ROUTES SUPPORT
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
/// GET
|
// GET
|
||||||
|
//
|
||||||
//Get list of jobs
|
|
||||||
internal async Task<List<JobOperationsFetchInfo>> GetJobListAsync()
|
internal async Task<List<JobOperationsFetchInfo>> GetJobListAsync()
|
||||||
{
|
{
|
||||||
List<JobOperationsFetchInfo> ret = new List<JobOperationsFetchInfo>();
|
List<JobOperationsFetchInfo> ret = new List<JobOperationsFetchInfo>();
|
||||||
@@ -86,27 +83,57 @@ namespace AyaNova.Biz
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get list of logs for job
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
//GET LOG OF ALL JOBS FOR CLIENT
|
||||||
|
//
|
||||||
internal async Task<List<JobOperationsLogInfoItem>> GetAllJobsLogsListAsync()
|
internal async Task<List<JobOperationsLogInfoItem>> GetAllJobsLogsListAsync()
|
||||||
{
|
{
|
||||||
List<JobOperationsLogInfoItem> ret = new List<JobOperationsLogInfoItem>();
|
List<JobOperationsLogInfoItem> ret = new List<JobOperationsLogInfoItem>();
|
||||||
|
var l = await ct.OpsJobLog
|
||||||
var l = await ct.OpsJobLog
|
.OrderByDescending(z => z.Created)
|
||||||
.OrderByDescending(z => z.Created)
|
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
foreach (OpsJobLog i in l)
|
foreach (OpsJobLog i in l)
|
||||||
{
|
{
|
||||||
|
|
||||||
JobOperationsLogInfoItem o = new JobOperationsLogInfoItem();
|
JobOperationsLogInfoItem o = new JobOperationsLogInfoItem();
|
||||||
o.Created = i.Created;
|
o.Created = i.Created;
|
||||||
o.StatusText = i.StatusText;
|
o.StatusText = i.StatusText;
|
||||||
ret.Add(o);
|
ret.Add(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//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.TestJob:
|
||||||
|
await ProcessTestJobAsync(job);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new System.ArgumentOutOfRangeException($"JobOperationsBiz.HandleJob-> Invalid job type{job.JobType.ToString()}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ProcessTestJobAsync(OpsJob job)
|
||||||
|
{
|
||||||
|
var sleepTime = 30 * 1000;
|
||||||
|
await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Running, ct);
|
||||||
|
await JobsBiz.LogJobAsync(job.GId, $"ProcessTestJob started, sleeping for {sleepTime} seconds...", ct);
|
||||||
|
await Task.Delay(sleepTime);
|
||||||
|
await JobsBiz.LogJobAsync(job.GId, "ProcessTestJob done sleeping setting job to finished", ct);
|
||||||
|
await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Completed, ct);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion controller routes
|
#endregion controller routes
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace AyaNova.Biz
|
|||||||
public enum JobType : int
|
public enum JobType : int
|
||||||
{
|
{
|
||||||
NotSet = 0,
|
NotSet = 0,
|
||||||
TestWidgetJob = 1,//test job for unit testing
|
TestJob = 1,//test job for unit and OPS admin testing
|
||||||
CoreJobSweeper = 2,
|
CoreJobSweeper = 2,
|
||||||
SeedTestData = 4,
|
SeedTestData = 4,
|
||||||
BulkCoreBizObjectOperation = 5,
|
BulkCoreBizObjectOperation = 5,
|
||||||
|
|||||||
@@ -412,8 +412,8 @@ namespace AyaNova.Biz
|
|||||||
await CoreJobBackup.DoWorkAsync(ct, true);
|
await CoreJobBackup.DoWorkAsync(ct, true);
|
||||||
await UpdateJobStatusAsync(job.GId, JobStatus.Completed, ct);
|
await UpdateJobStatusAsync(job.GId, JobStatus.Completed, ct);
|
||||||
break;
|
break;
|
||||||
case JobType.TestWidgetJob:
|
case JobType.TestJob:
|
||||||
o = (IJobObject)BizObjectFactory.GetBizObject(AyaType.Widget, ct);
|
o = (IJobObject)BizObjectFactory.GetBizObject(AyaType.ServerJob, ct);
|
||||||
break;
|
break;
|
||||||
case JobType.SeedTestData:
|
case JobType.SeedTestData:
|
||||||
o = (IJobObject)BizObjectFactory.GetBizObject(AyaType.TrialSeeder, ct);
|
o = (IJobObject)BizObjectFactory.GetBizObject(AyaType.TrialSeeder, ct);
|
||||||
|
|||||||
@@ -293,33 +293,12 @@ namespace AyaNova.Biz
|
|||||||
case JobType.BulkCoreBizObjectOperation:
|
case JobType.BulkCoreBizObjectOperation:
|
||||||
await ProcessBulkJobAsync(job);
|
await ProcessBulkJobAsync(job);
|
||||||
break;
|
break;
|
||||||
case JobType.TestWidgetJob:
|
|
||||||
await ProcessTestJobAsync(job);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
throw new System.ArgumentOutOfRangeException($"WidgetBiz.HandleJob-> Invalid job type{job.JobType.ToString()}");
|
throw new System.ArgumentOutOfRangeException($"WidgetBiz.HandleJob-> Invalid job type{job.JobType.ToString()}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// /// Handle the test job
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="job"></param>
|
|
||||||
private async Task ProcessTestJobAsync(OpsJob job)
|
|
||||||
{
|
|
||||||
var sleepTime = 30 * 1000;
|
|
||||||
//Simulate a long running job here
|
|
||||||
await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Running, 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, "Widget ProcessTestJob done sleeping setting job to finished", ct);
|
|
||||||
await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Completed, ct);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private async Task ProcessBulkJobAsync(OpsJob job)
|
private async Task ProcessBulkJobAsync(OpsJob job)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user