This commit is contained in:
2020-01-27 21:47:54 +00:00
parent 3c9a6c8ea6
commit cbba819e84
8 changed files with 48 additions and 48 deletions

View File

@@ -62,8 +62,8 @@ namespace AyaNova.Biz
//basically any error condition during job processing should throw up an exception if it can't be handled //basically any error condition during job processing should throw up an exception if it can't be handled
List<ImportAyaNova7MapItem> importMap = new List<ImportAyaNova7MapItem>(); List<ImportAyaNova7MapItem> importMap = new List<ImportAyaNova7MapItem>();
JobsBiz.UpdateJobStatus(job.GId, JobStatus.Running, ct); JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Running, ct);
JobsBiz.LogJob(job.GId, $"ImportAyaNova7 starting", ct); JobsBiz.LogJobAsync(job.GId, $"ImportAyaNova7 starting", ct);
//Get the import filename from the jsondata //Get the import filename from the jsondata
JObject jobData = JObject.Parse(job.JobInfo); JObject jobData = JObject.Parse(job.JobInfo);
@@ -81,7 +81,7 @@ namespace AyaNova.Biz
//Erase all the data except for the license, schema and the manager user //Erase all the data except for the license, schema and the manager user
Microsoft.Extensions.Logging.ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger("ImportAyaNova7"); Microsoft.Extensions.Logging.ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger("ImportAyaNova7");
JobsBiz.LogJob(job.GId, "ImportAyaNova7 - Erasing data from database", ct); JobsBiz.LogJobAsync(job.GId, "ImportAyaNova7 - Erasing data from database", ct);
DbUtil.EmptyBizDataFromDatabaseForSeedingOrImporting(log); DbUtil.EmptyBizDataFromDatabaseForSeedingOrImporting(log);
@@ -173,8 +173,8 @@ namespace AyaNova.Biz
//---------------- //----------------
JobsBiz.LogJob(job.GId, "ImportAyaNova7 finished", ct); JobsBiz.LogJobAsync(job.GId, "ImportAyaNova7 finished", ct);
JobsBiz.UpdateJobStatus(job.GId, JobStatus.Completed, ct); JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Completed, ct);
} }
@@ -204,11 +204,11 @@ namespace AyaNova.Biz
{ {
if (importTask != "main") if (importTask != "main")
{ {
JobsBiz.LogJob(jobId, $"Starting import sub-task {importTask} of {entryStartsWith} objects", ct); JobsBiz.LogJobAsync(jobId, $"Starting import sub-task {importTask} of {entryStartsWith} objects", ct);
} }
else else
{ {
JobsBiz.LogJob(jobId, $"Starting import of {entryStartsWith} objects", ct); JobsBiz.LogJobAsync(jobId, $"Starting import of {entryStartsWith} objects", ct);
} }
var jList = FileUtil.ZipGetUtilityArchiveEntriesAsJsonObjects(zipObjectList, importFileName); var jList = FileUtil.ZipGetUtilityArchiveEntriesAsJsonObjects(zipObjectList, importFileName);
@@ -235,11 +235,11 @@ namespace AyaNova.Biz
{ {
if (importTask != "main") if (importTask != "main")
{ {
JobsBiz.LogJob(jobId, $"Successfully ran import subtask {importTask} on {importCount.ToString()} of {zipObjectList.Count.ToString()} {entryStartsWith} objects", ct); JobsBiz.LogJobAsync(jobId, $"Successfully ran import subtask {importTask} on {importCount.ToString()} of {zipObjectList.Count.ToString()} {entryStartsWith} objects", ct);
} }
else else
{ {
JobsBiz.LogJob(jobId, $"Successfully imported {importCount.ToString()} of {zipObjectList.Count.ToString()} {entryStartsWith} objects", ct); JobsBiz.LogJobAsync(jobId, $"Successfully imported {importCount.ToString()} of {zipObjectList.Count.ToString()} {entryStartsWith} objects", ct);
} }
} }
@@ -247,11 +247,11 @@ namespace AyaNova.Biz
{ {
if (importTask != "main") if (importTask != "main")
{ {
JobsBiz.LogJob(jobId, $"Failed to run import subtask {importTask} on {notImportCount.ToString()} of {zipObjectList.Count.ToString()} {entryStartsWith} objects", ct); JobsBiz.LogJobAsync(jobId, $"Failed to run import subtask {importTask} on {notImportCount.ToString()} of {zipObjectList.Count.ToString()} {entryStartsWith} objects", ct);
} }
else else
{ {
JobsBiz.LogJob(jobId, $"Did not import {notImportCount.ToString()} of {zipObjectList.Count.ToString()} {entryStartsWith} objects", ct); JobsBiz.LogJobAsync(jobId, $"Did not import {notImportCount.ToString()} of {zipObjectList.Count.ToString()} {entryStartsWith} objects", ct);
} }
} }
} }
@@ -267,7 +267,7 @@ namespace AyaNova.Biz
if (zipObjectList.Count > 0) if (zipObjectList.Count > 0)
{ {
JobsBiz.LogJob(jobId, $"Starting import to TAGS of {entryStartsWith} objects", ct); JobsBiz.LogJobAsync(jobId, $"Starting import to TAGS of {entryStartsWith} objects", ct);
var jList = FileUtil.ZipGetUtilityArchiveEntriesAsJsonObjects(zipObjectList, importFileName); var jList = FileUtil.ZipGetUtilityArchiveEntriesAsJsonObjects(zipObjectList, importFileName);
foreach (JObject j in jList) foreach (JObject j in jList)
@@ -327,7 +327,7 @@ namespace AyaNova.Biz
if (importCount > 0) if (importCount > 0)
{ {
JobsBiz.LogJob(jobId, $"Successfully imported as TAGS {importCount.ToString()} of {zipObjectList.Count.ToString()} {entryStartsWith} objects", ct); JobsBiz.LogJobAsync(jobId, $"Successfully imported as TAGS {importCount.ToString()} of {zipObjectList.Count.ToString()} {entryStartsWith} objects", ct);
} }
} }
} }

View File

@@ -168,7 +168,7 @@ namespace AyaNova.Biz
{ {
foreach (OpsJob jobToBeDeleted in jobsForObject) foreach (OpsJob jobToBeDeleted in jobsForObject)
{ {
await removeJobAndLogsAsync(ct, jobToBeDeleted.GId); await RemoveJobAndLogsAsync(ct, jobToBeDeleted.GId);
} }
// Commit transaction if all commands succeed, transaction will auto-rollback // Commit transaction if all commands succeed, transaction will auto-rollback
@@ -196,7 +196,7 @@ namespace AyaNova.Biz
{ {
try try
{ {
await removeJobAndLogsAsync(ct, jobId); await RemoveJobAndLogsAsync(ct, jobId);
// Commit transaction if all commands succeed, transaction will auto-rollback // Commit transaction if all commands succeed, transaction will auto-rollback
// when disposed if either commands fails // when disposed if either commands fails
transaction.Commit(); transaction.Commit();
@@ -215,7 +215,7 @@ namespace AyaNova.Biz
/// </summary> /// </summary>
/// <param name="ct"></param> /// <param name="ct"></param>
/// <param name="jobIdToBeDeleted"></param> /// <param name="jobIdToBeDeleted"></param>
private static async Task removeJobAndLogsAsync(AyContext ct, Guid jobIdToBeDeleted) private static async Task RemoveJobAndLogsAsync(AyContext ct, Guid jobIdToBeDeleted)
{ {
// //delete logs // //delete logs
// await ct.Database.ExecuteSqlCommandAsync("delete from aopsjoblog where jobid = {0}", new object[] { jobIdToBeDeleted }); // await ct.Database.ExecuteSqlCommandAsync("delete from aopsjoblog where jobid = {0}", new object[] { jobIdToBeDeleted });
@@ -223,7 +223,7 @@ namespace AyaNova.Biz
// //delete the job // //delete the job
// await ct.Database.ExecuteSqlCommandAsync("delete from aopsjob where gid = {0}", new object[] { jobIdToBeDeleted }); // await ct.Database.ExecuteSqlCommandAsync("delete from aopsjob where gid = {0}", new object[] { jobIdToBeDeleted });
//delete logs //delete logs
await ct.Database.ExecuteSqlInterpolatedAsync($"delete from aopsjoblog where jobid = {jobIdToBeDeleted}"); await ct.Database.ExecuteSqlInterpolatedAsync($"delete from aopsjoblog where jobid = {jobIdToBeDeleted}");
//delete the job //delete the job
@@ -241,9 +241,9 @@ namespace AyaNova.Biz
/// </summary> /// </summary>
/// <param name="jobId"></param> /// <param name="jobId"></param>
/// <param name="statusText"></param> /// <param name="statusText"></param>
internal static OpsJobLog LogJob(Guid jobId, string statusText) internal static async Task<OpsJobLog> LogJobAsync(Guid jobId, string statusText)
{ {
return LogJob(jobId, statusText, null); return await LogJobAsync(jobId, statusText, null);
} }
/// <summary> /// <summary>
@@ -252,7 +252,7 @@ namespace AyaNova.Biz
/// <param name="jobId"></param> /// <param name="jobId"></param>
/// <param name="statusText"></param> /// <param name="statusText"></param>
/// <param name="ct"></param> /// <param name="ct"></param>
internal static OpsJobLog LogJob(Guid jobId, string statusText, AyContext ct) internal static async Task<OpsJobLog> LogJobAsync(Guid jobId, string statusText, AyContext ct)
{ {
if (ct == null) if (ct == null)
ct = ServiceProviderProvider.DBContext; ct = ServiceProviderProvider.DBContext;
@@ -261,8 +261,8 @@ namespace AyaNova.Biz
OpsJobLog newObj = new OpsJobLog(); OpsJobLog newObj = new OpsJobLog();
newObj.JobId = jobId; newObj.JobId = jobId;
newObj.StatusText = statusText; newObj.StatusText = statusText;
ct.OpsJobLog.Add(newObj); await ct.OpsJobLog.AddAsync(newObj);
ct.SaveChanges(); await ct.SaveChangesAsync();
return newObj; return newObj;
} }
@@ -273,12 +273,12 @@ namespace AyaNova.Biz
/// <param name="jobId"></param> /// <param name="jobId"></param>
/// <param name="newStatus"></param> /// <param name="newStatus"></param>
/// <param name="ct"></param> /// <param name="ct"></param>
internal static OpsJob UpdateJobStatus(Guid jobId, JobStatus newStatus, AyContext ct) internal static async Task<OpsJob> UpdateJobStatusAsync(Guid jobId, JobStatus newStatus, AyContext ct)
{ {
var oFromDb = ct.OpsJob.SingleOrDefault(m => m.GId == jobId); var oFromDb = await ct.OpsJob.SingleOrDefaultAsync(m => m.GId == jobId);
if (oFromDb == null) return null; if (oFromDb == null) return null;
oFromDb.JobStatus = newStatus; oFromDb.JobStatus = newStatus;
ct.SaveChanges(); await ct.SaveChangesAsync();
return oFromDb; return oFromDb;
} }
#endregion Job ops #endregion Job ops
@@ -309,9 +309,9 @@ namespace AyaNova.Biz
catch (Exception ex) catch (Exception ex)
{ {
log.LogError(ex, $"ProcessJobs::Exclusive -> job {j.Name} failed with exception"); log.LogError(ex, $"ProcessJobs::Exclusive -> job {j.Name} failed with exception");
LogJob(j.GId, "Job failed with errors:", ct); await LogJobAsync(j.GId, "Job failed with errors:", ct);
LogJob(j.GId, ExceptionUtil.ExtractAllExceptionMessages(ex), ct); await LogJobAsync(j.GId, ExceptionUtil.ExtractAllExceptionMessages(ex), ct);
UpdateJobStatus(j.GId, JobStatus.Failed, ct); UpdateJobStatusAsync(j.GId, JobStatus.Failed, ct);
} }
} }
//Get a list of non-exlusive jobs that are due //Get a list of non-exlusive jobs that are due
@@ -335,9 +335,9 @@ namespace AyaNova.Biz
catch (Exception ex) catch (Exception ex)
{ {
log.LogError(ex, $"ProcessJobs::Shared -> job {j.Name} failed with exception"); log.LogError(ex, $"ProcessJobs::Shared -> job {j.Name} failed with exception");
LogJob(j.GId, "Job failed with errors:", ct); await LogJobAsync(j.GId, "Job failed with errors:", ct);
LogJob(j.GId, ExceptionUtil.ExtractAllExceptionMessages(ex), ct); await LogJobAsync(j.GId, ExceptionUtil.ExtractAllExceptionMessages(ex), ct);
UpdateJobStatus(j.GId, JobStatus.Failed, ct); UpdateJobStatusAsync(j.GId, JobStatus.Failed, ct);
} }
} }
@@ -352,9 +352,9 @@ namespace AyaNova.Biz
await CoreJobMetricsSnapshot.DoJobAsync(ct); await CoreJobMetricsSnapshot.DoJobAsync(ct);
//License check //License check
long CurrentActiveCount = UserBiz.ActiveCount; long CurrentActiveCount = await UserBiz.ActiveCountAsync();
long LicensedUserCount = AyaNova.Core.License.ActiveKey.ActiveNumber; long LicensedUserCount = AyaNova.Core.License.ActiveKey.ActiveNumber;
// log.LogInformation("JobsBiz::Checking license active count"); // log.LogInformation("JobsBiz::Checking license active count");
if (CurrentActiveCount > LicensedUserCount) if (CurrentActiveCount > LicensedUserCount)
{ {
var msg = $"E1020 - Active count exceeded capacity"; var msg = $"E1020 - Active count exceeded capacity";

View File

@@ -546,7 +546,7 @@ namespace AyaNova.Biz
if (await LocaleExistsAsync(SourceLocaleName)) if (await LocaleExistsAsync(SourceLocaleName))
{ {
//If there are any validation errors, log in joblog and move on //If there are any validation errors, log in joblog and move on
JobsBiz.LogJob(jobId, $"LocaleBiz::ImportV7Async -> - Locale \"{SourceLocaleName}\" already exists in database, can not import over an existing locale", ct); JobsBiz.LogJobAsync(jobId, $"LocaleBiz::ImportV7Async -> - Locale \"{SourceLocaleName}\" already exists in database, can not import over an existing locale", ct);
return false; return false;
} }

View File

@@ -64,17 +64,17 @@ namespace AyaNova.Biz
//FOR NOW NOT ASYNC so faking it at end of this method //FOR NOW NOT ASYNC so faking it at end of this method
JobsBiz.UpdateJobStatus(job.GId, JobStatus.Running, ct); JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Running, ct);
JobsBiz.LogJob(job.GId, $"Starting...", ct); JobsBiz.LogJobAsync(job.GId, $"Starting...", ct);
//Get the import filename from the jsondata //Get the import filename from the jsondata
JObject jobData = JObject.Parse(job.JobInfo); JObject jobData = JObject.Parse(job.JobInfo);
var seedLevel = (Seeder.SeedLevel)jobData["seedLevel"].Value<int>(); var seedLevel = (Seeder.SeedLevel)jobData["seedLevel"].Value<int>();
var timeZoneOffset = jobData["timeZoneOffset"].Value<decimal>(); var timeZoneOffset = jobData["timeZoneOffset"].Value<decimal>();
Seeder.SeedDatabase(seedLevel, job.GId, timeZoneOffset); Seeder.SeedDatabase(seedLevel, job.GId, timeZoneOffset);
JobsBiz.LogJob(job.GId, "Finished.", ct); JobsBiz.LogJobAsync(job.GId, "Finished.", ct);
JobsBiz.UpdateJobStatus(job.GId, JobStatus.Completed, ct); JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Completed, ct);
NO, BAD! Convert the logjob etc above to async //NO, BAD! Convert the logjob etc above to async
//await Task.CompletedTask; //await Task.CompletedTask;
} }

View File

@@ -810,7 +810,7 @@ namespace AyaNova.Biz
if (HasErrors) if (HasErrors)
{ {
//If there are any validation errors, log in joblog and move on //If there are any validation errors, log in joblog and move on
JobsBiz.LogJob(jobId, $" -> import object \"{i.Name}\" source id {V7Id.ToString()} failed validation and was not imported: {GetErrorsAsString()} ", ct); JobsBiz.LogJobAsync(jobId, $" -> import object \"{i.Name}\" source id {V7Id.ToString()} failed validation and was not imported: {GetErrorsAsString()} ", ct);
//This is a fundamental problem with the import as users are required for many things so bomb out entirely //This is a fundamental problem with the import as users are required for many things so bomb out entirely
//other things might be able to work around but this is too serious //other things might be able to work around but this is too serious

View File

@@ -329,13 +329,13 @@ namespace AyaNova.Biz
{ {
var sleepTime = 30 * 1000; var sleepTime = 30 * 1000;
//Simulate a long running job here //Simulate a long running job here
JobsBiz.UpdateJobStatus(job.GId, JobStatus.Running, ct); JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Running, ct);
JobsBiz.LogJob(job.GId, $"WidgetBiz::ProcessTestJob started, sleeping for {sleepTime} seconds...", ct); JobsBiz.LogJobAsync(job.GId, $"WidgetBiz::ProcessTestJob started, sleeping for {sleepTime} seconds...", ct);
//Uncomment this to test if the job prevents other routes from running //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 //result is NO it doesn't prevent other requests, so we are a-ok for now
await Task.Delay(sleepTime); await Task.Delay(sleepTime);
JobsBiz.LogJob(job.GId, "WidgetBiz::ProcessTestJob done sleeping setting job to finished", ct); JobsBiz.LogJobAsync(job.GId, "WidgetBiz::ProcessTestJob done sleeping setting job to finished", ct);
JobsBiz.UpdateJobStatus(job.GId, JobStatus.Completed, ct); JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Completed, ct);
} }

View File

@@ -111,9 +111,9 @@ namespace AyaNova.Biz
foreach (OpsJob j in jobs) foreach (OpsJob j in jobs)
{ {
//OPSMETRIC //OPSMETRIC
JobsBiz.LogJob(j.GId, "Job took too long to run - setting to failed", ct); JobsBiz.LogJobAsync(j.GId, "Job took too long to run - setting to failed", ct);
log.LogError($"Job found job stuck in running status and set to failed: deadline={dtRunningDeadline.ToString()}, jobId={j.GId.ToString()}, jobname={j.Name}, jobtype={j.JobType.ToString()}, jobObjectType={j.ObjectType.ToString()}, jobObjectId={j.ObjectId.ToString()}"); log.LogError($"Job found job stuck in running status and set to failed: deadline={dtRunningDeadline.ToString()}, jobId={j.GId.ToString()}, jobname={j.Name}, jobtype={j.JobType.ToString()}, jobObjectType={j.ObjectType.ToString()}, jobObjectId={j.ObjectId.ToString()}");
JobsBiz.UpdateJobStatus(j.GId, JobStatus.Failed, ct); JobsBiz.UpdateJobStatusAsync(j.GId, JobStatus.Failed, ct);
} }
} }

View File

@@ -394,7 +394,7 @@ namespace AyaNova.Util
{ {
log.LogError(ex, "Seeder:SeedDatabase error during ops"); log.LogError(ex, "Seeder:SeedDatabase error during ops");
if (LogJob) if (LogJob)
JobsBiz.LogJob(JobId, $"Seeder:SeedDatabase error during ops\r\n{ex.Message}"); JobsBiz.LogJobAsync(JobId, $"Seeder:SeedDatabase error during ops\r\n{ex.Message}");
throw ex; throw ex;
} }
finally finally
@@ -412,7 +412,7 @@ namespace AyaNova.Util
{ {
log.LogInformation(msg); log.LogInformation(msg);
if (LogJob) if (LogJob)
JobsBiz.LogJob(JobId, msg); JobsBiz.LogJobAsync(JobId, msg);
} }