This commit is contained in:
2020-06-15 18:52:15 +00:00
parent e58a59f730
commit 69030bd767
6 changed files with 51 additions and 66 deletions

2
.vscode/launch.json vendored
View File

@@ -44,7 +44,7 @@
//"AYANOVA_LOG_LEVEL": "Debug", //"AYANOVA_LOG_LEVEL": "Debug",
"AYANOVA_DEFAULT_TRANSLATION": "en", "AYANOVA_DEFAULT_TRANSLATION": "en",
//TRANSLATION MUST BE en for Integration TESTING //TRANSLATION MUST BE en for Integration TESTING
//"AYANOVA_PERMANENTLY_ERASE_DATABASE": "true", "AYANOVA_PERMANENTLY_ERASE_DATABASE": "true",
"AYANOVA_DB_CONNECTION": "Server=localhost;Username=postgres;Password=raven;Database=AyaNova;", "AYANOVA_DB_CONNECTION": "Server=localhost;Username=postgres;Password=raven;Database=AyaNova;",
"AYANOVA_USE_URLS": "http://*:7575;", "AYANOVA_USE_URLS": "http://*:7575;",
"AYANOVA_FOLDER_USER_FILES": "c:\\temp\\RavenTestData\\userfiles", "AYANOVA_FOLDER_USER_FILES": "c:\\temp\\RavenTestData\\userfiles",

View File

@@ -7,6 +7,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using AyaNova.Models; using AyaNova.Models;
using AyaNova.Util; using AyaNova.Util;
using AyaNova.Api.ControllerHelpers;
using AyaNova.Biz;
using AyaNova.Util;
namespace AyaNova.Biz namespace AyaNova.Biz
@@ -155,9 +158,36 @@ namespace AyaNova.Biz
ActivelyProcessing = true; ActivelyProcessing = true;
try try
{ {
//## Critical internal jobs //### Critical internal jobs, these run even if there is a license related serverlock
await CoreJobSweeper.DoSweepAsync(); //LICENSE FETCH
await CoreJobLicense.DoWorkAsync(); await CoreJobLicense.DoWorkAsync();
//"SHENANIGAN" CHECK
if (await UserBiz.ActiveCountAsync() > AyaNova.Core.License.ActiveKey.ActiveNumber)
{
var msg = $"E1020 - Active count exceeded capacity";
ServiceProviderProvider.ServerState.SetSystemLock(msg);
log.LogCritical(msg);
return;
}
//METRICS
CoreJobMetricsSnapshot.DoWork();
//### Server state dependent jobs
ApiServerState serverState = ServiceProviderProvider.ServerState;
//system lock (no license) is a complete deal breaker for continuation beyond here
if (serverState.IsSystemLocked) return;
//TODO: NOTIFICATIONS
//await CoreJobNotify.DoWorkAsync();
//BACKUP
await CoreJobBackup.DoWorkAsync();
//JOB SWEEPER
await CoreJobSweeper.DoWorkAsync();
//### API Open only jobs
if (!serverState.IsOpen) return;
//BIZOBJECT DYNAMIC JOBS //BIZOBJECT DYNAMIC JOBS
//get a list of exclusive jobs that are due to happen //get a list of exclusive jobs that are due to happen
@@ -167,10 +197,7 @@ namespace AyaNova.Biz
{ {
try try
{ {
//System.Diagnostics.Debug.WriteLine($"JobsBiz processing exclusive biz job {j.Name}");
await ProcessJobAsync(j); await ProcessJobAsync(j);
//Capture metrics
CoreJobMetricsSnapshot.DoJob();
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -181,26 +208,6 @@ namespace AyaNova.Biz
} }
} }
//System.Diagnostics.Debug.WriteLine($"JobsBiz processing exclusive license check");
//License check
long CurrentActiveCount = await UserBiz.ActiveCountAsync();
long LicensedUserCount = AyaNova.Core.License.ActiveKey.ActiveNumber;
// log.LogInformation("JobsBiz::Checking license active count");
if (CurrentActiveCount > LicensedUserCount)
{
var msg = $"E1020 - Active count exceeded capacity";
ServiceProviderProvider.ServerState.SetSystemLock(msg);
log.LogCritical(msg);
return;
}
//backup
//System.Diagnostics.Debug.WriteLine($"JobsBiz processing backup");
await CoreJobBackup.DoWorkAsync();//sb exclusive
//System.Diagnostics.Debug.WriteLine($"JobsBiz processing metrics snapshotter");
//Capture metrics
CoreJobMetricsSnapshot.DoJob();
/////////////////////////////////////// ///////////////////////////////////////
//NON-EXCLUSIVE JOBS //NON-EXCLUSIVE JOBS
@@ -223,14 +230,6 @@ namespace AyaNova.Biz
await UpdateJobStatusAsync(j.GId, JobStatus.Failed); await UpdateJobStatusAsync(j.GId, JobStatus.Failed);
} }
} }
//Capture metrics
CoreJobMetricsSnapshot.DoJob();
//TODO: NOTIFICATIONS
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@@ -19,15 +19,20 @@ namespace AyaNova.Biz
{ {
private static ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger("CoreJobLicense"); private static ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger("CoreJobLicense");
private static DateTime _lastCheck = DateTime.MinValue; private static DateTime _lastCheck = DateTime.MinValue;
private static TimeSpan FAST_TRACK = new TimeSpan(0, 0, 30, 0); #if (DEBUG)
private static TimeSpan FAST_TRACK = new TimeSpan(0, 1, 0);
private static TimeSpan SLOW_TRACK = new TimeSpan(0, 5, 0);
#else
private static TimeSpan FAST_TRACK = new TimeSpan(0, 30, 0);
private static TimeSpan SLOW_TRACK = new TimeSpan(24, 0, 0); private static TimeSpan SLOW_TRACK = new TimeSpan(24, 0, 0);
#endif
//////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////
// DoWork // DoWork
// //
public static async Task DoWorkAsync() public static async Task DoWorkAsync()
{ {
log.LogTrace("Job starting"); log.LogTrace("Job starting");
var tsSinceLastCheck = DateTime.UtcNow - _lastCheck; var tsSinceLastCheck = DateTime.UtcNow - _lastCheck;
//which track are we on? //which track are we on?
@@ -71,7 +76,7 @@ namespace AyaNova.Biz
//Eventlog //Eventlog
await EventLogProcessor.LogEventToDatabaseAsync(new Event(1, 0, AyaType.License, AyaEvent.LicenseFetch, "FromCoreJob"), ct); await EventLogProcessor.LogEventToDatabaseAsync(new Event(1, 0, AyaType.License, AyaEvent.LicenseFetch, "FromCoreJob"), ct);
} }
if(ret!="notfound") if (ret != "notfound")
{ {
//I'm thinking do not log internally failed except as trace event as this would fill up log file //I'm thinking do not log internally failed except as trace event as this would fill up log file
//instead if they have a license issue they can do manual fetch and then that will log so they can see error //instead if they have a license issue they can do manual fetch and then that will log so they can see error

View File

@@ -35,7 +35,7 @@ namespace AyaNova.Biz
//////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////
// //
// //
public static void DoJob() public static void DoWork()
{ {

View File

@@ -27,7 +27,7 @@ namespace AyaNova.Biz
//////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////
// DoSweep // DoSweep
// //
public static async Task DoSweepAsync() public static async Task DoWorkAsync()
{ {
//This will get triggered roughly every minute, but we don't want to sweep that frequently //This will get triggered roughly every minute, but we don't want to sweep that frequently
if (DateTime.UtcNow - lastSweep < SWEEP_EVERY_INTERVAL) if (DateTime.UtcNow - lastSweep < SWEEP_EVERY_INTERVAL)

View File

@@ -2,9 +2,7 @@ using System.Threading;
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using AyaNova.Api.ControllerHelpers;
using AyaNova.Biz; using AyaNova.Biz;
using AyaNova.Util;
namespace AyaNova.Generator namespace AyaNova.Generator
{ {
@@ -48,49 +46,32 @@ namespace AyaNova.Generator
while (!stoppingToken.IsCancellationRequested) while (!stoppingToken.IsCancellationRequested)
{ {
if (!justStarted) if (!justStarted)//give it a pause to settle on boot
{ {
log.LogDebug($"GeneratorService task doing background work."); log.LogDebug($"GeneratorService running jobs");
ApiServerState serverState = ServiceProviderProvider.ServerState;
//================================================================= //=================================================================
try try
{ {
if (!serverState.IsOpen) await JobsBiz.ProcessJobsAsync();
{
log.LogDebug($"GeneratorService: ServerState is closed returning without processing jobs, will try again next iteration");
}
else
{
//System.Diagnostics.Debug.WriteLine($"### GENERATE calling JobsBiz.ProcessJobs");
//Capture metrics
CoreJobMetricsSnapshot.DoJob();
await JobsBiz.ProcessJobsAsync();
//Capture metrics again, (calling repeatedly won't increase metrics but will ensure it doesn't miss frequency of capturing)
CoreJobMetricsSnapshot.DoJob();
//System.Diagnostics.Debug.WriteLine($"### GENERATE BACK FROM calling JobsBiz.ProcessJobs");
}
} }
catch (Exception ex) catch (Exception ex)
{ {
log.LogError(ex, "Generate::ProcessJobs result in exception error "); log.LogError(ex, "Generate::ProcessJobs result in exception error ");
} }
//================================================================= //=================================================================
} }
await Task.Delay((GENERATE_SECONDS * 1000), stoppingToken); await Task.Delay((GENERATE_SECONDS * 1000), stoppingToken);
justStarted = false; justStarted = false;
} }
log.LogDebug($"GeneratorService is stopping");
log.LogDebug($"GeneratorService background task is stopping.");
} }
public override Task StopAsync(CancellationToken stoppingToken) public override Task StopAsync(CancellationToken stoppingToken)
{ {
log.LogDebug($"GeneratorService StopAsync triggered."); log.LogDebug($"GeneratorService StopAsync triggered");
return Task.FromResult(0); return Task.FromResult(0);
// Run your graceful clean-up actions // Run any needed clean-up actions
} }
}//eoc }//eoc
}//eons }//eons