much fuckery
This commit is contained in:
@@ -6,6 +6,7 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using AyaNova.Models;
|
||||
using AyaNova.Api.ControllerHelpers;
|
||||
using AyaNova.Biz;
|
||||
using AyaNova.Util;
|
||||
|
||||
namespace AyaNova.Generator
|
||||
{
|
||||
@@ -27,6 +28,7 @@ namespace AyaNova.Generator
|
||||
// private readonly ApiServerState serverState;
|
||||
|
||||
private readonly IServiceProvider provider;
|
||||
private const int MAXIMUM_TIME_ALLOWED_FOR_PROCESSING_ALL_JOBS = 1 * 60 * 1000;//1 minutes TEST TEST TEST #####
|
||||
|
||||
#if(DEBUG)
|
||||
private const int GENERATE_SECONDS = 5;
|
||||
@@ -53,7 +55,11 @@ namespace AyaNova.Generator
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
todo: improve this
|
||||
it should timeout: https://stackoverflow.com/questions/23476576/cancellationtoken-timeout-vs-task-delay-and-timeout
|
||||
it should never stop running no matter what unless teh server shuts down
|
||||
*/
|
||||
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
@@ -73,32 +79,37 @@ namespace AyaNova.Generator
|
||||
{
|
||||
log.LogDebug($"GeneratorService task doing background work.");
|
||||
|
||||
using (IServiceScope scope = provider.CreateScope())
|
||||
ApiServerState serverState = ServiceProviderProvider.ServerState;
|
||||
//=================================================================
|
||||
try
|
||||
{
|
||||
AyContext ct = scope.ServiceProvider.GetRequiredService<AyContext>();
|
||||
ApiServerState serverState = scope.ServiceProvider.GetRequiredService<ApiServerState>();
|
||||
|
||||
|
||||
|
||||
//=================================================================
|
||||
try
|
||||
if (!serverState.IsOpen)
|
||||
{
|
||||
if (!serverState.IsOpen)
|
||||
{
|
||||
log.LogDebug($"GeneratorService: ServerState is closed returning without processing jobs, will try again next iteration");
|
||||
}
|
||||
else
|
||||
{
|
||||
await JobsBiz.ProcessJobsAsync(ct, serverState);
|
||||
}
|
||||
log.LogDebug($"GeneratorService: ServerState is closed returning without processing jobs, will try again next iteration");
|
||||
}
|
||||
catch (Exception ex)
|
||||
else
|
||||
{
|
||||
log.LogError(ex, "Generate::ProcessJobs result in exception error ");
|
||||
System.Diagnostics.Debug.WriteLine($"### GENERATE calling JobsBiz.ProcessJobs");
|
||||
|
||||
//Before anything capture metrics
|
||||
// await CoreJobMetricsSnapshot.DoJobAsync(ct);
|
||||
//Task.Run(() => CoreJobMetricsSnapshot.DoJob());
|
||||
//deliberately calling this non-async
|
||||
//it needs to be fast and efficient
|
||||
CoreJobMetricsSnapshot.DoJob();
|
||||
//TODO: this should be big timeout and then inside the process jobs each job has it's own timeout
|
||||
await TaskUtil.WithTimeoutAfterStart(ctoken => JobsBiz.ProcessJobsAsync(ctoken), TimeSpan.FromMilliseconds(MAXIMUM_TIME_ALLOWED_FOR_PROCESSING_ALL_JOBS));
|
||||
// await JobsBiz.ProcessJobsAsync(ct, serverState);
|
||||
System.Diagnostics.Debug.WriteLine($"### GENERATE BACK FROM calling JobsBiz.ProcessJobs");
|
||||
}
|
||||
//=================================================================
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.LogError(ex, "Generate::ProcessJobs result in exception error ");
|
||||
|
||||
}
|
||||
//=================================================================
|
||||
|
||||
}
|
||||
await Task.Delay((GENERATE_SECONDS * 1000), stoppingToken);
|
||||
justStarted = false;
|
||||
|
||||
Reference in New Issue
Block a user