auto license fetching now and generator more solid
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
using System;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using AyaNova.Biz;
|
using AyaNova.Biz;
|
||||||
namespace AyaNova.Api.ControllerHelpers
|
namespace AyaNova.Api.ControllerHelpers
|
||||||
{
|
{
|
||||||
@@ -35,6 +33,7 @@ namespace AyaNova.Api.ControllerHelpers
|
|||||||
|
|
||||||
public ApiServerState()
|
public ApiServerState()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -45,7 +44,7 @@ namespace AyaNova.Api.ControllerHelpers
|
|||||||
//Only SuperUser account (id=1) can login or do anything, treats as if server was set to closed even if they change it to open
|
//Only SuperUser account (id=1) can login or do anything, treats as if server was set to closed even if they change it to open
|
||||||
//only way to reset it is to fetch a valid license
|
//only way to reset it is to fetch a valid license
|
||||||
//
|
//
|
||||||
var msg=$"{reason}\r\nOnly *the* SuperUser account can login to make changes";
|
var msg = $"{reason}\r\nOnly *the* SuperUser account can login to make changes";
|
||||||
SetState(ServerState.OpsOnly, msg);
|
SetState(ServerState.OpsOnly, msg);
|
||||||
SYSTEM_LOCK = true;
|
SYSTEM_LOCK = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,11 +21,15 @@ namespace AyaNova
|
|||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//Boot lock for generator
|
||||||
|
ServerGlobalOpsSettingsCache.BOOTING = true;
|
||||||
|
|
||||||
//Get config
|
//Get config
|
||||||
var config = new ConfigurationBuilder().AddEnvironmentVariables().AddCommandLine(args).Build();
|
var config = new ConfigurationBuilder().AddEnvironmentVariables().AddCommandLine(args).Build();
|
||||||
ServerBootConfig.SetConfiguration(config);
|
ServerBootConfig.SetConfiguration(config);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#region Initialize Logging
|
#region Initialize Logging
|
||||||
//NOTE: there is a logging issue that breaks all this with .net 3.1 hostbuilder vs webhostbuilder but webhostbuilder will be deprecated so we need to work around it
|
//NOTE: there is a logging issue that breaks all this with .net 3.1 hostbuilder vs webhostbuilder but webhostbuilder will be deprecated so we need to work around it
|
||||||
//the discussion about that is here: https://github.com/aspnet/AspNetCore/issues/9337
|
//the discussion about that is here: https://github.com/aspnet/AspNetCore/issues/9337
|
||||||
|
|||||||
@@ -305,7 +305,8 @@ namespace AyaNova
|
|||||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||||
//
|
//
|
||||||
public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IWebHostEnvironment env,
|
public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IWebHostEnvironment env,
|
||||||
AyContext dbContext, IApiVersionDescriptionProvider provider, AyaNova.Api.ControllerHelpers.ApiServerState apiServerState, IServiceProvider serviceProvider)
|
AyContext dbContext, IApiVersionDescriptionProvider provider, AyaNova.Api.ControllerHelpers.ApiServerState apiServerState,
|
||||||
|
IServiceProvider serviceProvider)
|
||||||
{
|
{
|
||||||
_newLog.LogDebug("Configuring request pipeline...");
|
_newLog.LogDebug("Configuring request pipeline...");
|
||||||
|
|
||||||
@@ -601,10 +602,14 @@ namespace AyaNova
|
|||||||
_newLog.LogInformation($"License - [{AyaNova.Core.License.LicenseInfoLogFormat}]");
|
_newLog.LogInformation($"License - [{AyaNova.Core.License.LicenseInfoLogFormat}]");
|
||||||
|
|
||||||
|
|
||||||
|
//Boot lock for generator
|
||||||
|
ServerGlobalOpsSettingsCache.BOOTING=false;
|
||||||
|
|
||||||
//Open up the server for visitors
|
//Open up the server for visitors
|
||||||
|
_newLog.LogDebug("Setting server state open");
|
||||||
apiServerState.SetOpen();
|
apiServerState.SetOpen();
|
||||||
|
|
||||||
|
|
||||||
//final startup log
|
//final startup log
|
||||||
_newLog.LogInformation("Boot complete - server open");
|
_newLog.LogInformation("Boot complete - server open");
|
||||||
|
|
||||||
|
|||||||
@@ -161,14 +161,7 @@ namespace AyaNova.Biz
|
|||||||
//### Critical internal jobs, these run even if there is a license related serverlock
|
//### Critical internal jobs, these run even if there is a license related serverlock
|
||||||
//LICENSE FETCH
|
//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
|
//METRICS
|
||||||
CoreJobMetricsSnapshot.DoWork();
|
CoreJobMetricsSnapshot.DoWork();
|
||||||
|
|
||||||
@@ -178,6 +171,14 @@ namespace AyaNova.Biz
|
|||||||
//system lock (no license) is a complete deal breaker for continuation beyond here
|
//system lock (no license) is a complete deal breaker for continuation beyond here
|
||||||
if (serverState.IsSystemLocked) return;
|
if (serverState.IsSystemLocked) return;
|
||||||
|
|
||||||
|
//"SHENANIGAN" CHECK, note, must be here after systemlock because it relies on there being a license
|
||||||
|
if (await UserBiz.ActiveCountAsync() > AyaNova.Core.License.ActiveKey.ActiveNumber)
|
||||||
|
{
|
||||||
|
var msg = $"E1020 - Active count exceeded capacity";
|
||||||
|
ServiceProviderProvider.ServerState.SetSystemLock(msg);
|
||||||
|
log.LogCritical(msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
//TODO: NOTIFICATIONS
|
//TODO: NOTIFICATIONS
|
||||||
//await CoreJobNotify.DoWorkAsync();
|
//await CoreJobNotify.DoWorkAsync();
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using AyaNova.Biz;
|
using AyaNova.Biz;
|
||||||
|
using AyaNova.Util;
|
||||||
|
|
||||||
namespace AyaNova.Generator
|
namespace AyaNova.Generator
|
||||||
{
|
{
|
||||||
@@ -23,7 +24,11 @@ namespace AyaNova.Generator
|
|||||||
private const int GENERATE_SECONDS = 5;
|
private const int GENERATE_SECONDS = 5;
|
||||||
#else
|
#else
|
||||||
private const int GENERATE_SECONDS = 20;
|
private const int GENERATE_SECONDS = 20;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public GeneratorService(ILogger<GeneratorService> logger)
|
public GeneratorService(ILogger<GeneratorService> logger)
|
||||||
{
|
{
|
||||||
log = logger;
|
log = logger;
|
||||||
@@ -37,16 +42,16 @@ namespace AyaNova.Generator
|
|||||||
|
|
||||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||||
{
|
{
|
||||||
//don't immediately run the generator stuff on boot
|
|
||||||
bool justStarted = true;
|
|
||||||
log.LogDebug($"GeneratorService is starting.");
|
log.LogDebug($"GeneratorService is starting.");
|
||||||
|
|
||||||
stoppingToken.Register(() =>
|
stoppingToken.Register(() =>
|
||||||
log.LogDebug($" GeneratorService background task is stopping."));
|
log.LogDebug($" GeneratorService background task is stopping."));
|
||||||
|
|
||||||
|
|
||||||
while (!stoppingToken.IsCancellationRequested)
|
while (!stoppingToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
if (!justStarted)//give it a pause to settle on boot
|
if (!ServerGlobalOpsSettingsCache.BOOTING)
|
||||||
{
|
{
|
||||||
log.LogDebug($"GeneratorService running jobs");
|
log.LogDebug($"GeneratorService running jobs");
|
||||||
|
|
||||||
@@ -62,7 +67,6 @@ namespace AyaNova.Generator
|
|||||||
//=================================================================
|
//=================================================================
|
||||||
}
|
}
|
||||||
await Task.Delay((GENERATE_SECONDS * 1000), stoppingToken);
|
await Task.Delay((GENERATE_SECONDS * 1000), stoppingToken);
|
||||||
justStarted = false;
|
|
||||||
}
|
}
|
||||||
log.LogDebug($"GeneratorService is stopping");
|
log.LogDebug($"GeneratorService is stopping");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ namespace AyaNova.Models
|
|||||||
|
|
||||||
public class GlobalBizSettings
|
public class GlobalBizSettings
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public long Id { get; set; }//this is always 1 as there is only ever one single global biz object
|
public long Id { get; set; }//this is always 1 as there is only ever one single global biz object
|
||||||
public uint Concurrency { get; set; }
|
public uint Concurrency { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ namespace AyaNova.Util
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal static class ServerGlobalOpsSettingsCache
|
internal static class ServerGlobalOpsSettingsCache
|
||||||
{
|
{
|
||||||
|
//BOOT flag, set during boot and
|
||||||
|
//is used to control generator from starting
|
||||||
|
internal static bool BOOTING { get; set; }
|
||||||
|
|
||||||
internal static GlobalOpsBackupSettings Backup { get; set; }
|
internal static GlobalOpsBackupSettings Backup { get; set; }
|
||||||
internal static DateTime NextBackup { get; set; }
|
internal static DateTime NextBackup { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user