Inizio migrazione ProdService
This commit is contained in:
@@ -220,6 +220,16 @@
|
||||
MACHINABLE = 1,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tipo di code del Prod
|
||||
/// </summary>
|
||||
public enum ProdQueueType
|
||||
{
|
||||
waiting,
|
||||
running,
|
||||
done
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modalità raggruppamento (giornalieri, orari...)
|
||||
/// </summary>
|
||||
|
||||
@@ -104,6 +104,7 @@ namespace EgwCoreLib.Lux.Data
|
||||
services.TryAddSingleton<IConfigDataService, ConfigDataService>();
|
||||
services.TryAddSingleton<ICalcRequestService, CalcRequestService>();
|
||||
services.TryAddSingleton<IFileService, FileService>();
|
||||
services.TryAddSingleton<ProdService>();
|
||||
//services.TryAddSingleton<CalcRequestService>();
|
||||
|
||||
|
||||
|
||||
+28
-34
@@ -7,8 +7,9 @@ using NLog;
|
||||
using StackExchange.Redis;
|
||||
using System.Diagnostics;
|
||||
using static Egw.Window.Data.Enums;
|
||||
using static EgwCoreLib.Lux.Core.Enums;
|
||||
|
||||
namespace EgwCoreLib.Lux.Data.Services
|
||||
namespace EgwCoreLib.Lux.Data.Services.General
|
||||
{
|
||||
public class ProdService : BaseServ
|
||||
{
|
||||
@@ -28,13 +29,6 @@ namespace EgwCoreLib.Lux.Data.Services
|
||||
|
||||
#region Public Enums
|
||||
|
||||
public enum QueueType
|
||||
{
|
||||
waiting,
|
||||
running,
|
||||
done
|
||||
}
|
||||
|
||||
#endregion Public Enums
|
||||
|
||||
#region Public Methods
|
||||
@@ -56,7 +50,7 @@ namespace EgwCoreLib.Lux.Data.Services
|
||||
string currKey = $"{redisBaseKey}:{currRequest.EnvType}:{reqUid.Replace("/", ":")}";
|
||||
done = await _redisService.SetAsync(currKey, calcRequest.sProcessArgs);
|
||||
// invio ed accodo!
|
||||
var qWaitKey = qKey(currRequest.EnvType, QueueType.waiting);
|
||||
var qWaitKey = qKey(currRequest.EnvType, ProdQueueType.waiting);
|
||||
_redisService.QueuePush(qWaitKey, (RedisValue)reqUid);
|
||||
// dizionario richieste: è il serializzato dell'elenco degli UID da calcolare...
|
||||
List<RedisValue> currList = await _redisService.QueueListAllAsync(qWaitKey);
|
||||
@@ -101,7 +95,7 @@ namespace EgwCoreLib.Lux.Data.Services
|
||||
/// <param name="cEnv">environment richiesto</param>
|
||||
/// <param name="qType">tipo coda (default waiting)</param>
|
||||
/// <returns></returns>
|
||||
public async Task<string> GetNext(Constants.EXECENVIRONMENTS cEnv, QueueType qType = QueueType.waiting)
|
||||
public async Task<string> GetNext(Constants.EXECENVIRONMENTS cEnv, ProdQueueType qType = ProdQueueType.waiting)
|
||||
{
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
@@ -113,7 +107,7 @@ namespace EgwCoreLib.Lux.Data.Services
|
||||
{
|
||||
string reqUid = $"{rawReq}";
|
||||
// metto UID in coda running nella successiva.. se non ultima...
|
||||
if (qType < QueueType.running)
|
||||
if (qType < ProdQueueType.running)
|
||||
{
|
||||
// FixMe ToDo !!!: salvataggio data-ora per indicare avvio calcolo...
|
||||
_redisService.QueuePush(qKey(cEnv, qType + 1), (RedisValue)reqUid);
|
||||
@@ -138,31 +132,31 @@ namespace EgwCoreLib.Lux.Data.Services
|
||||
/// <param name="codJob">chiave da cercare x avanzarla</param>
|
||||
/// <param name="qType">coda di default a run --> done</param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> SetDone(Constants.EXECENVIRONMENTS cEnv, string codJob, QueueType qType = QueueType.running)
|
||||
public async Task<bool> SetDone(Constants.EXECENVIRONMENTS cEnv, string codJob, ProdQueueType qType = ProdQueueType.running)
|
||||
{
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
bool fatto = false;
|
||||
// recupero lista completa SENZA eliminare...
|
||||
var listRunning = await _redisService.QueueListAllAsync(qKey(cEnv, QueueType.running));
|
||||
var listRunning = await _redisService.QueueListAllAsync(qKey(cEnv, ProdQueueType.running));
|
||||
if (listRunning != null && listRunning.Contains(codJob))
|
||||
{
|
||||
var numRem = await _redisService.QueueRemoveAsync(qKey(cEnv, QueueType.running), (RedisValue)codJob);
|
||||
var numRem = await _redisService.QueueRemoveAsync(qKey(cEnv, ProdQueueType.running), (RedisValue)codJob);
|
||||
if (numRem > 0)
|
||||
{
|
||||
// elimino eventuali duplicati sulla coda di destinazione
|
||||
var listDone = await _redisService.QueueListAllAsync(qKey(cEnv, QueueType.done));
|
||||
var listDone = await _redisService.QueueListAllAsync(qKey(cEnv, ProdQueueType.done));
|
||||
if (listDone != null && listDone.Contains(codJob))
|
||||
{
|
||||
await _redisService.QueueRemoveAsync(qKey(cEnv, QueueType.done), (RedisValue)codJob);
|
||||
await _redisService.QueueRemoveAsync(qKey(cEnv, ProdQueueType.done), (RedisValue)codJob);
|
||||
}
|
||||
// accodo nuovi!
|
||||
var numAdd = _redisService.QueuePush(qKey(cEnv, QueueType.done), codJob);
|
||||
var numAdd = _redisService.QueuePush(qKey(cEnv, ProdQueueType.done), codJob);
|
||||
fatto = numAdd > 0;
|
||||
}
|
||||
}
|
||||
sw.Stop();
|
||||
Log.Info($"SetDone | env: {cEnv} | qFrom: {qKey(cEnv, QueueType.running)} | reqUid: {codJob} | fatto: {fatto} | {sw.Elapsed.TotalMilliseconds:N3} ms");
|
||||
Log.Info($"SetDone | env: {cEnv} | qFrom: {qKey(cEnv, ProdQueueType.running)} | reqUid: {codJob} | fatto: {fatto} | {sw.Elapsed.TotalMilliseconds:N3} ms");
|
||||
return fatto;
|
||||
}
|
||||
|
||||
@@ -172,7 +166,7 @@ namespace EgwCoreLib.Lux.Data.Services
|
||||
/// <param name="cEnv">environment richiesto</param>
|
||||
/// <param name="qType">tipo coda (default waiting)</param>
|
||||
/// <returns></returns>
|
||||
public async Task<long> QueueLen(Constants.EXECENVIRONMENTS cEnv, QueueType qType = QueueType.waiting)
|
||||
public async Task<long> QueueLen(Constants.EXECENVIRONMENTS cEnv, ProdQueueType qType = ProdQueueType.waiting)
|
||||
{
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
@@ -189,7 +183,7 @@ namespace EgwCoreLib.Lux.Data.Services
|
||||
/// <param name="cEnv">environment richiesto</param>
|
||||
/// <param name="qType">tipo coda</param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<RedisValue>> QueueListAllAsync(Constants.EXECENVIRONMENTS cEnv, QueueType qType)
|
||||
public async Task<List<RedisValue>> QueueListAllAsync(Constants.EXECENVIRONMENTS cEnv, ProdQueueType qType)
|
||||
{
|
||||
RedisKey rKey = qKey(cEnv, qType);
|
||||
List<RedisValue> currList = await _redisService.QueueListAllAsync(rKey);
|
||||
@@ -202,7 +196,7 @@ namespace EgwCoreLib.Lux.Data.Services
|
||||
/// <param name="cEnv">environment richiesto</param>
|
||||
/// <param name="qType">tipo coda</param>
|
||||
/// <returns></returns>
|
||||
public bool QueueReset(Constants.EXECENVIRONMENTS cEnv, QueueType qType)
|
||||
public bool QueueReset(Constants.EXECENVIRONMENTS cEnv, ProdQueueType qType)
|
||||
{
|
||||
RedisKey rKey = qKey(cEnv, qType);
|
||||
bool answ = _redisService.QueueReset(rKey);
|
||||
@@ -215,7 +209,7 @@ namespace EgwCoreLib.Lux.Data.Services
|
||||
/// <param name="cEnv">environment richiesto</param>
|
||||
/// <param name="qType">tipo coda</param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> QueueResetAsync(Constants.EXECENVIRONMENTS cEnv, QueueType qType)
|
||||
public async Task<bool> QueueResetAsync(Constants.EXECENVIRONMENTS cEnv, ProdQueueType qType)
|
||||
{
|
||||
RedisKey rKey = qKey(cEnv, qType);
|
||||
bool answ = await _redisService.QueueResetAsync(rKey);
|
||||
@@ -230,7 +224,7 @@ namespace EgwCoreLib.Lux.Data.Services
|
||||
public async Task<bool> ResetRunning(Constants.EXECENVIRONMENTS cEnv)
|
||||
{
|
||||
bool fatto = false;
|
||||
RedisKey rKey = qKey(cEnv, QueueType.running);
|
||||
RedisKey rKey = qKey(cEnv, ProdQueueType.running);
|
||||
var listRunning = await _redisService.QueuePopAllAsync(rKey);
|
||||
if (listRunning != null)
|
||||
{
|
||||
@@ -239,7 +233,7 @@ namespace EgwCoreLib.Lux.Data.Services
|
||||
if (item.HasValue)
|
||||
{
|
||||
// FixMe ToDo !!!: salvataggio data-ora per indicare avvio calcolo...
|
||||
_redisService.QueuePush(qKey(cEnv, QueueType.waiting), item);
|
||||
_redisService.QueuePush(qKey(cEnv, ProdQueueType.waiting), item);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -256,13 +250,13 @@ namespace EgwCoreLib.Lux.Data.Services
|
||||
public async Task<bool> ReRunJob(Constants.EXECENVIRONMENTS cEnv, string codJob)
|
||||
{
|
||||
bool fatto = false;
|
||||
RedisKey rKey = qKey(cEnv, QueueType.running);
|
||||
RedisKey rKey = qKey(cEnv, ProdQueueType.running);
|
||||
// recupero lista completa SENZA eliminare...
|
||||
var listRunning = await _redisService.QueueListAllAsync(rKey);
|
||||
// se non trova usa coda Done...
|
||||
if (listRunning == null || !listRunning.Contains(codJob))
|
||||
{
|
||||
rKey = qKey(cEnv, QueueType.done);
|
||||
rKey = qKey(cEnv, ProdQueueType.done);
|
||||
// recupero lista completa SENZA eliminare...
|
||||
listRunning = await _redisService.QueueListAllAsync(rKey);
|
||||
}
|
||||
@@ -271,7 +265,7 @@ namespace EgwCoreLib.Lux.Data.Services
|
||||
var numRem = await _redisService.QueueRemoveAsync(rKey, (RedisValue)codJob);
|
||||
if (numRem > 0)
|
||||
{
|
||||
var numAdd = _redisService.QueuePush(qKey(cEnv, QueueType.waiting), codJob);
|
||||
var numAdd = _redisService.QueuePush(qKey(cEnv, ProdQueueType.waiting), codJob);
|
||||
fatto = numAdd > 0;
|
||||
}
|
||||
}
|
||||
@@ -288,7 +282,7 @@ namespace EgwCoreLib.Lux.Data.Services
|
||||
{
|
||||
bool fatto = false;
|
||||
#if false
|
||||
RedisKey rKey = qKey(QueueType.running);
|
||||
RedisKey rKey = qKey(ProdQueueType.running);
|
||||
// recupero lista completa SENZA eliminare...
|
||||
var listRunning = await _redisService.QueueListAllAsync(rKey);
|
||||
if (listRunning != null && listRunning.Contains(codJob))
|
||||
@@ -296,7 +290,7 @@ namespace EgwCoreLib.Lux.Data.Services
|
||||
var numRem = await _redisService.QueueRemoveAsync(rKey, (RedisValue)codJob);
|
||||
if (numRem > 0)
|
||||
{
|
||||
var numAdd = _redisService.QueuePush(qKey(QueueType.waiting), codJob);
|
||||
var numAdd = _redisService.QueuePush(qKey(ProdQueueType.waiting), codJob);
|
||||
fatto = numAdd > 0;
|
||||
}
|
||||
}
|
||||
@@ -328,20 +322,20 @@ namespace EgwCoreLib.Lux.Data.Services
|
||||
/// <param name="cEnvir"></param>
|
||||
/// <param name="qType"></param>
|
||||
/// <returns></returns>
|
||||
private string qKey(Constants.EXECENVIRONMENTS cEnvir, QueueType qType)
|
||||
private string qKey(Constants.EXECENVIRONMENTS cEnvir, ProdQueueType qType)
|
||||
{
|
||||
RedisKey rKey = (RedisKey)$"{redisBaseKey}:{cEnvir}:CalcQueue";
|
||||
switch (qType)
|
||||
{
|
||||
case QueueType.waiting:
|
||||
case ProdQueueType.waiting:
|
||||
rKey = (RedisKey)$"{redisBaseKey}:{cEnvir}:CalcQueue:Wait";
|
||||
break;
|
||||
|
||||
case QueueType.running:
|
||||
case ProdQueueType.running:
|
||||
rKey = (RedisKey)$"{redisBaseKey}:{cEnvir}:CalcQueue:Run";
|
||||
break;
|
||||
|
||||
case QueueType.done:
|
||||
case ProdQueueType.done:
|
||||
rKey = (RedisKey)$"{redisBaseKey}:{cEnvir}:CalcQueue:Done";
|
||||
break;
|
||||
|
||||
@@ -396,7 +390,7 @@ namespace EgwCoreLib.Lux.Data.Services
|
||||
}
|
||||
if (!string.IsNullOrEmpty(rKey))
|
||||
{
|
||||
await SetDone(cEnvir, rKey, QueueType.running);
|
||||
await SetDone(cEnvir, rKey, ProdQueueType.running);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using EgwCoreLib.Lux.Data.Services;
|
||||
using EgwCoreLib.Lux.Data.Services.General;
|
||||
using EgwCoreLib.Lux.Data.Services.General;
|
||||
using EgwMultiEngineManager.Data;
|
||||
using Lux.API.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -7,7 +6,7 @@ using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using static EgwCoreLib.Lux.Data.Services.ProdService;
|
||||
using static EgwCoreLib.Lux.Core.Enums;
|
||||
|
||||
namespace Lux.API.Controllers
|
||||
{
|
||||
@@ -182,7 +181,7 @@ namespace Lux.API.Controllers
|
||||
/// <param name="type">Tipo coda (default waiting)</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("qlen/{envir}/{type}")]
|
||||
public async Task<IActionResult> QueueLen(string envir, QueueType type = QueueType.waiting)
|
||||
public async Task<IActionResult> QueueLen(string envir, ProdQueueType type = ProdQueueType.waiting)
|
||||
{
|
||||
Constants.EXECENVIRONMENTS cEnvir = Constants.EXECENVIRONMENTS.WINDOW;
|
||||
Enum.TryParse(envir, out cEnvir);
|
||||
@@ -204,9 +203,9 @@ namespace Lux.API.Controllers
|
||||
Constants.EXECENVIRONMENTS cEnvir = Constants.EXECENVIRONMENTS.WINDOW;
|
||||
Enum.TryParse(envir, out cEnvir);
|
||||
Dictionary<string, long> queueStatus = new Dictionary<string, long>();
|
||||
long numDone = await PService.QueueLen(cEnvir, QueueType.done);
|
||||
long numRun = await PService.QueueLen(cEnvir, QueueType.running);
|
||||
long numWait = await PService.QueueLen(cEnvir, QueueType.waiting);
|
||||
long numDone = await PService.QueueLen(cEnvir, ProdQueueType.done);
|
||||
long numRun = await PService.QueueLen(cEnvir, ProdQueueType.running);
|
||||
long numWait = await PService.QueueLen(cEnvir, ProdQueueType.waiting);
|
||||
// simulo status...
|
||||
queueStatus.Add("waiting", numWait);
|
||||
queueStatus.Add("running", numRun);
|
||||
|
||||
@@ -156,9 +156,6 @@ builder.Services.AddDbContextFactory<DataLayerContext>(options =>
|
||||
// registrazione in blocco servizi con metodo extension custom
|
||||
builder.Services.AddLuxData(connectionString);
|
||||
|
||||
// servizi Singleton (no DB)
|
||||
builder.Services.AddSingleton<ProdService>();
|
||||
|
||||
// servizi con dipendenze" ma Scoped
|
||||
builder.Services.AddScoped<ExternalMessageProcessor>();
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ using NLog;
|
||||
using StackExchange.Redis;
|
||||
using System.Diagnostics;
|
||||
using static Egw.Window.Data.Enums;
|
||||
using static EgwCoreLib.Lux.Core.Enums;
|
||||
|
||||
namespace Lux.API.Services
|
||||
{
|
||||
@@ -212,7 +213,7 @@ namespace Lux.API.Services
|
||||
}
|
||||
// sistemo code, definendo nuova key...
|
||||
string qKey = $"{QuestionModes.ORDER}:{QuestionOrderSubModes.BALANCE}:{UID}.{refGroup}";
|
||||
await _prodService.SetDone(retData.ExecEnvironment, qKey, ProdService.QueueType.running);
|
||||
await _prodService.SetDone(retData.ExecEnvironment, qKey, ProdQueueType.running);
|
||||
// reinvio in redis (cache + channel)
|
||||
await cacheService.SaveProdBalanceAsync(UID, retData.ExecEnvironment, rawBalance);
|
||||
saved = true;
|
||||
|
||||
@@ -11,6 +11,7 @@ using EgwCoreLib.Lux.Data.Services.Sales;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.JSInterop;
|
||||
using NLog;
|
||||
using static EgwCoreLib.Lux.Core.Enums;
|
||||
|
||||
namespace Lux.UI.Components.Pages
|
||||
{
|
||||
@@ -193,7 +194,7 @@ namespace Lux.UI.Components.Pages
|
||||
return;
|
||||
if (EditStateRec != null)
|
||||
{
|
||||
await PService.QueueResetAsync(EditStateRec.Envir, ProdService.QueueType.waiting);
|
||||
await PService.QueueResetAsync(EditStateRec.Envir, ProdQueueType.waiting);
|
||||
await UpdateJobQueue(EditStateRec.Envir);
|
||||
}
|
||||
}
|
||||
@@ -577,9 +578,9 @@ namespace Lux.UI.Components.Pages
|
||||
private async Task UpdateJobQueue(EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS envir)
|
||||
{
|
||||
// aggiorno coda corrente x display...
|
||||
var currQueueWait = await PService.QueueListAllAsync(envir, ProdService.QueueType.waiting);
|
||||
var currQueueRun = await PService.QueueListAllAsync(envir, ProdService.QueueType.running);
|
||||
var currQueueDone = await PService.QueueListAllAsync(envir, ProdService.QueueType.done);
|
||||
var currQueueWait = await PService.QueueListAllAsync(envir, ProdQueueType.waiting);
|
||||
var currQueueRun = await PService.QueueListAllAsync(envir, ProdQueueType.running);
|
||||
var currQueueDone = await PService.QueueListAllAsync(envir, ProdQueueType.done);
|
||||
// converto x display...
|
||||
JobQueueWait = currQueueWait.Select(x => $"{x}").ToList();
|
||||
JobQueueRun = currQueueRun.Select(x => $"{x}").ToList();
|
||||
|
||||
@@ -184,9 +184,6 @@ builder.Services.AddIdentityCore<ApplicationUser>(options => options.SignIn.Requ
|
||||
|
||||
builder.Services.AddSingleton<IEmailSender<ApplicationUser>, IdentityNoOpEmailSender>();
|
||||
|
||||
// Aggiunta servizi specifici
|
||||
builder.Services.AddSingleton<ProdService>();
|
||||
|
||||
// aggiunta componenti Radzen
|
||||
builder.Services.AddRadzenComponents();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user