This commit is contained in:
96
server/AyaNova/biz/TrialBiz.cs
Normal file
96
server/AyaNova/biz/TrialBiz.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using EnumsNET;
|
||||
using AyaNova.Util;
|
||||
using AyaNova.Api.ControllerHelpers;
|
||||
using AyaNova.Biz;
|
||||
using AyaNova.Models;
|
||||
|
||||
|
||||
namespace AyaNova.Biz
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Handle data seeding and other trial ops
|
||||
/// </summary>
|
||||
internal class TrialBiz : BizObject, IJobObject
|
||||
{
|
||||
private readonly AyContext ct;
|
||||
private readonly long userId;
|
||||
private readonly AuthorizationRoles userRoles;
|
||||
// private readonly ApiServerState serverState;
|
||||
|
||||
internal TrialBiz(AyContext dbcontext, long currentUserId, AuthorizationRoles UserRoles)
|
||||
{
|
||||
ct = dbcontext;
|
||||
userId = currentUserId;
|
||||
userRoles = UserRoles;
|
||||
//serverState = apiServerState;, ApiServerState apiServerState
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//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
|
||||
|
||||
//There might be future other job types so doing it like this for all biz job handlers for now
|
||||
switch (job.JobType)
|
||||
{
|
||||
case JobType.SeedTestData:
|
||||
await ProcessSeedTestData(job);
|
||||
// ProcessSeedTestData(job);
|
||||
break;
|
||||
default:
|
||||
throw new System.ArgumentOutOfRangeException($"TrialBiz.HandleJobAsync -> Invalid job type{job.JobType.ToString()}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Handle the job
|
||||
/// </summary>
|
||||
/// <param name="job"></param>
|
||||
private async Task ProcessSeedTestData(OpsJob job)
|
||||
{//
|
||||
//NOTE: If this code throws an exception the caller 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
|
||||
|
||||
|
||||
//FOR NOW NOT ASYNC so faking it at end of this method
|
||||
|
||||
|
||||
JobsBiz.UpdateJobStatus(job.GId, JobStatus.Running, ct);
|
||||
JobsBiz.LogJob(job.GId, $"Starting...", ct);
|
||||
|
||||
//Get the import filename from the jsondata
|
||||
JObject jobData = JObject.Parse(job.JobInfo);
|
||||
var seedLevel = (Seeder.SeedLevel)jobData["seedLevel"].Value<int>();
|
||||
Seeder.SeedDatabase(ct, seedLevel);
|
||||
JobsBiz.LogJob(job.GId, "Finished.", ct);
|
||||
JobsBiz.UpdateJobStatus(job.GId, JobStatus.Completed, ct);
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Other job handlers here...
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
}//eoc
|
||||
|
||||
|
||||
}//eons
|
||||
|
||||
Reference in New Issue
Block a user