diff --git a/WebDoorCreator.API/Controllers/QueueController.cs b/WebDoorCreator.API/Controllers/QueueController.cs index c94819a..da489a7 100644 --- a/WebDoorCreator.API/Controllers/QueueController.cs +++ b/WebDoorCreator.API/Controllers/QueueController.cs @@ -36,6 +36,9 @@ namespace WebDoorCreator.API.Controllers var actProc = await QDataServ.NumRequestProcessing(); answ.Add("processing", actProc); + + var actDone = await QDataServ.NumRequestDone(); + answ.Add("done", actDone); return answ; } @@ -86,7 +89,7 @@ namespace WebDoorCreator.API.Controllers answ.Add("processing", actProc); var actDone = await QDataServ.RequestDone(); - answ.Add("done", actProc); + answ.Add("done", actDone); return answ; } diff --git a/WebDoorCreator.Data/Services/QueueDataService.cs b/WebDoorCreator.Data/Services/QueueDataService.cs index 1823114..fba0070 100644 --- a/WebDoorCreator.Data/Services/QueueDataService.cs +++ b/WebDoorCreator.Data/Services/QueueDataService.cs @@ -83,6 +83,25 @@ namespace WebDoorCreator.Data.Services return answ; } + /// + /// Get # of calculation request done + /// + public async Task NumRequestDone() + { + long numReq = 0; + string source = "REDIS"; + Dictionary dictResult = new Dictionary(); + // cerco da cache + RedisKey currKey = new RedisKey(Constants.CALC_REQ_DONE); + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + numReq = await redisDb.HashLengthAsync(currKey); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"NumRequestDone | {source} in: {ts.TotalMilliseconds} ms"); + return numReq; + } + /// /// Get # of calculation request pending /// @@ -149,7 +168,7 @@ namespace WebDoorCreator.Data.Services long numReq = 0; Dictionary dictResult = new Dictionary(); // cerco da cache - RedisKey currKey = new RedisKey(Constants.CALC_REQ_DDF_CACHE); + RedisKey currKey = new RedisKey(Constants.CALC_REQ_DONE); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); numReq = redisDb.HashLength(currKey); @@ -166,6 +185,7 @@ namespace WebDoorCreator.Data.Services Log.Debug($"RequestDone | {source} in: {ts.TotalMilliseconds} ms"); return dictResult; } + /// /// Remove for single hash record /// @@ -288,6 +308,76 @@ namespace WebDoorCreator.Data.Services return numReq; } + /// + /// Reset to queue request all processing/processed data + /// + /// Dictionary of DoorId, saveVersNumb + public async Task ResetQueue() + { + bool fatto = false; + await Task.Delay(1); + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + // cerco le richieste processing + RedisKey currKey = new RedisKey(Constants.CALC_REQ_PROC); + var rawData = await redisDb.HashGetAllAsync(currKey); + foreach (var item in rawData) + { + await RequestPendingUpsert(item.Name!, item.Value!); + await RequestProcessingRemove(item.Name!); + fatto = true; + } + // cerco le richieste processed + currKey = new RedisKey(Constants.CALC_REQ_DONE); + rawData = await redisDb.HashGetAllAsync(currKey); + foreach (var item in rawData) + { + await RequestPendingUpsert(item.Name!, item.Value!); + await RequestDoneRemove(item.Name!); + fatto = true; + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"ResetQueue | REDIS in: {ts.TotalMilliseconds} ms"); + return fatto; + } + + /// + /// Salvo elenco risultati elaborazioni (modalità boolean di esecuzione corretta) + /// + /// Risultati elaborazioni in formato CalcResultDTO + /// + public async Task SaveProcessingResult(List calcResults) + { + bool answ = true; + await Task.Delay(1); + if (calcResults != null && calcResults.Count > 0) + { + string sDoorId = ""; + string sCurrVers = ""; + foreach (var calcTask in calcResults) + { + // solo se risultato valido... + if (calcTask.Validated) + { + // salvo in area REDIS + var doorData = calcTask.DoorIdVers.Split("."); + sDoorId = doorData.Length > 0 ? doorData[0] : ""; + sCurrVers = doorData.Length > 0 ? doorData[1] : ""; + RedisKey currSvgKey = new RedisKey($"{Constants.CALC_REQ_SVG_CACHE}:{sDoorId}:{sCurrVers}"); + await redisDb.StringSetAsync(currSvgKey, calcTask.SvgGen, DayLongCache); + // invio il FINTO messaggio di ritorno... + string retMess = $"{sDoorId}:{sCurrVers}"; + CalcDonePipe.saveAndSendMessage(Constants.LAST_CALC_DONE_KEY, retMess); + // sposto tra le 2 code + await RequestProcessingRemove(sDoorId); + await RequestDoneUpsert(sDoorId, sCurrVers); + } + } + } + return answ; + } + /// /// Invio richiesta di calcolo per la porta indicata, dato il suo DDF /// @@ -356,7 +446,7 @@ namespace WebDoorCreator.Data.Services await Task.Delay(300); string retMess = $"{sDoorId}:{sCurrVers}"; // invio il FINTO messaggio di ritorno... - CalcDonePipe.saveAndSendMessage(Constants.LAST_CALC_DONE_KEY, retMess); + CalcDonePipe.saveAndSendMessage(Constants.LAST_CALC_DONE_KEY, retMess); #endif return currVers; @@ -402,76 +492,6 @@ namespace WebDoorCreator.Data.Services return dictResult; } - /// - /// Reset to queue request all processing/processed data - /// - /// Dictionary of DoorId, saveVersNumb - public async Task ResetQueue() - { - bool fatto = false; - await Task.Delay(1); - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - // cerco le richieste processing - RedisKey currKey = new RedisKey(Constants.CALC_REQ_PROC); - var rawData = await redisDb.HashGetAllAsync(currKey); - foreach (var item in rawData) - { - await RequestPendingUpsert(item.Name!, item.Value!); - await RequestProcessingRemove(item.Name!); - fatto = true; - } - // cerco le richieste processed - currKey = new RedisKey(Constants.CALC_REQ_DONE); - rawData = await redisDb.HashGetAllAsync(currKey); - foreach (var item in rawData) - { - await RequestPendingUpsert(item.Name!, item.Value!); - await RequestDoneRemove(item.Name!); - fatto = true; - } - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"ResetQueue | REDIS in: {ts.TotalMilliseconds} ms"); - return fatto; - } - - /// - /// Salvo elenco risultati elaborazioni (modalità boolean di esecuzione corretta) - /// - /// Risultati elaborazioni in formato CalcResultDTO - /// - public async Task SaveProcessingResult(List calcResults) - { - bool answ = true; - await Task.Delay(1); - if (calcResults != null && calcResults.Count > 0) - { - string sDoorId = ""; - string sCurrVers = ""; - foreach (var calcTask in calcResults) - { - // solo se risultato valido... - if (calcTask.Validated) - { - // salvo in area REDIS - var doorData = calcTask.DoorIdVers.Split("."); - sDoorId = doorData.Length > 0 ? doorData[0] : ""; - sCurrVers = doorData.Length > 0 ? doorData[0] : ""; - RedisKey currSvgKey = new RedisKey($"{Constants.CALC_REQ_SVG_CACHE}:{sDoorId}:{sCurrVers}"); - await redisDb.StringSetAsync(currSvgKey, calcTask.SvgGen, DayLongCache); - // invio il FINTO messaggio di ritorno... - string retMess = $"{sDoorId}:{sCurrVers}"; - CalcDonePipe.saveAndSendMessage(Constants.LAST_CALC_DONE_KEY, retMess); - // sposto tra le 2 code - await RequestProcessingRemove(sDoorId); - await RequestDoneUpsert(sDoorId, sCurrVers); - } - } - } - return answ; - } - #endregion Public Methods #region Protected Fields diff --git a/WeebDoorCreator.SDK/WDC.cs b/WeebDoorCreator.SDK/WDC.cs index 39fe920..8cb154f 100644 --- a/WeebDoorCreator.SDK/WDC.cs +++ b/WeebDoorCreator.SDK/WDC.cs @@ -127,8 +127,8 @@ namespace WeebDoorCreator.SDK /// public Dictionary queueStatus() { - var rawData = callUrlGet(urlActLenght); Dictionary returnData = new Dictionary(); + var rawData = callUrlGet(urlActLenght); if (rawData != "ERR") { returnData = JsonConvert.DeserializeObject>(rawData);