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
List<ImportAyaNova7MapItem> importMap = new List<ImportAyaNova7MapItem>();
JobsBiz.UpdateJobStatus(job.GId, JobStatus.Running, ct);
JobsBiz.LogJob(job.GId, $"ImportAyaNova7 starting", ct);
JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Running, ct);
JobsBiz.LogJobAsync(job.GId, $"ImportAyaNova7 starting", ct);
//Get the import filename from the jsondata
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
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);
@@ -173,8 +173,8 @@ namespace AyaNova.Biz
//----------------
JobsBiz.LogJob(job.GId, "ImportAyaNova7 finished", ct);
JobsBiz.UpdateJobStatus(job.GId, JobStatus.Completed, ct);
JobsBiz.LogJobAsync(job.GId, "ImportAyaNova7 finished", ct);
JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Completed, ct);
}
@@ -204,11 +204,11 @@ namespace AyaNova.Biz
{
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
{
JobsBiz.LogJob(jobId, $"Starting import of {entryStartsWith} objects", ct);
JobsBiz.LogJobAsync(jobId, $"Starting import of {entryStartsWith} objects", ct);
}
var jList = FileUtil.ZipGetUtilityArchiveEntriesAsJsonObjects(zipObjectList, importFileName);
@@ -235,11 +235,11 @@ namespace AyaNova.Biz
{
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
{
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")
{
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
{
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)
{
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);
foreach (JObject j in jList)
@@ -327,7 +327,7 @@ namespace AyaNova.Biz
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)
{
await removeJobAndLogsAsync(ct, jobToBeDeleted.GId);
await RemoveJobAndLogsAsync(ct, jobToBeDeleted.GId);
}
// Commit transaction if all commands succeed, transaction will auto-rollback
@@ -196,7 +196,7 @@ namespace AyaNova.Biz
{
try
{
await removeJobAndLogsAsync(ct, jobId);
await RemoveJobAndLogsAsync(ct, jobId);
// Commit transaction if all commands succeed, transaction will auto-rollback
// when disposed if either commands fails
transaction.Commit();
@@ -215,7 +215,7 @@ namespace AyaNova.Biz
/// </summary>
/// <param name="ct"></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
// await ct.Database.ExecuteSqlCommandAsync("delete from aopsjoblog where jobid = {0}", new object[] { jobIdToBeDeleted });
@@ -223,7 +223,7 @@ namespace AyaNova.Biz
// //delete the job
// 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}");
//delete the job
@@ -241,9 +241,9 @@ namespace AyaNova.Biz
/// </summary>
/// <param name="jobId"></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>
@@ -252,7 +252,7 @@ namespace AyaNova.Biz
/// <param name="jobId"></param>
/// <param name="statusText"></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)
ct = ServiceProviderProvider.DBContext;
@@ -261,8 +261,8 @@ namespace AyaNova.Biz
OpsJobLog newObj = new OpsJobLog();
newObj.JobId = jobId;
newObj.StatusText = statusText;
ct.OpsJobLog.Add(newObj);
ct.SaveChanges();
await ct.OpsJobLog.AddAsync(newObj);
await ct.SaveChangesAsync();
return newObj;
}
@@ -273,12 +273,12 @@ namespace AyaNova.Biz
/// <param name="jobId"></param>
/// <param name="newStatus"></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;
oFromDb.JobStatus = newStatus;
ct.SaveChanges();
await ct.SaveChangesAsync();
return oFromDb;
}
#endregion Job ops
@@ -309,9 +309,9 @@ namespace AyaNova.Biz
catch (Exception ex)
{
log.LogError(ex, $"ProcessJobs::Exclusive -> job {j.Name} failed with exception");
LogJob(j.GId, "Job failed with errors:", ct);
LogJob(j.GId, ExceptionUtil.ExtractAllExceptionMessages(ex), ct);
UpdateJobStatus(j.GId, JobStatus.Failed, ct);
await LogJobAsync(j.GId, "Job failed with errors:", ct);
await LogJobAsync(j.GId, ExceptionUtil.ExtractAllExceptionMessages(ex), ct);
UpdateJobStatusAsync(j.GId, JobStatus.Failed, ct);
}
}
//Get a list of non-exlusive jobs that are due
@@ -335,9 +335,9 @@ namespace AyaNova.Biz
catch (Exception ex)
{
log.LogError(ex, $"ProcessJobs::Shared -> job {j.Name} failed with exception");
LogJob(j.GId, "Job failed with errors:", ct);
LogJob(j.GId, ExceptionUtil.ExtractAllExceptionMessages(ex), ct);
UpdateJobStatus(j.GId, JobStatus.Failed, ct);
await LogJobAsync(j.GId, "Job failed with errors:", ct);
await LogJobAsync(j.GId, ExceptionUtil.ExtractAllExceptionMessages(ex), ct);
UpdateJobStatusAsync(j.GId, JobStatus.Failed, ct);
}
}
@@ -352,9 +352,9 @@ namespace AyaNova.Biz
await CoreJobMetricsSnapshot.DoJobAsync(ct);
//License check
long CurrentActiveCount = UserBiz.ActiveCount;
long CurrentActiveCount = await UserBiz.ActiveCountAsync();
long LicensedUserCount = AyaNova.Core.License.ActiveKey.ActiveNumber;
// log.LogInformation("JobsBiz::Checking license active count");
// log.LogInformation("JobsBiz::Checking license active count");
if (CurrentActiveCount > LicensedUserCount)
{
var msg = $"E1020 - Active count exceeded capacity";

View File

@@ -546,7 +546,7 @@ namespace AyaNova.Biz
if (await LocaleExistsAsync(SourceLocaleName))
{
//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;
}

View File

@@ -64,17 +64,17 @@ namespace AyaNova.Biz
//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);
JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Running, ct);
JobsBiz.LogJobAsync(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>();
var timeZoneOffset = jobData["timeZoneOffset"].Value<decimal>();
Seeder.SeedDatabase(seedLevel, job.GId, timeZoneOffset);
JobsBiz.LogJob(job.GId, "Finished.", ct);
JobsBiz.UpdateJobStatus(job.GId, JobStatus.Completed, ct);
NO, BAD! Convert the logjob etc above to async
JobsBiz.LogJobAsync(job.GId, "Finished.", ct);
JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Completed, ct);
//NO, BAD! Convert the logjob etc above to async
//await Task.CompletedTask;
}

View File

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

View File

@@ -111,9 +111,9 @@ namespace AyaNova.Biz
foreach (OpsJob j in jobs)
{
//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()}");
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");
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;
}
finally
@@ -412,7 +412,7 @@ namespace AyaNova.Util
{
log.LogInformation(msg);
if (LogJob)
JobsBiz.LogJob(JobId, msg);
JobsBiz.LogJobAsync(JobId, msg);
}