Merge branch 'develop' of https://gitlab.steamware.net/egalware-web/special/webdoorcreator into develop
This commit is contained in:
+640
-629
File diff suppressed because it is too large
Load Diff
@@ -37,6 +37,9 @@ namespace WebDoorCreator.API.Controllers
|
||||
var actProc = await QDataServ.NumRequestProcessing();
|
||||
answ.Add("processing", actProc);
|
||||
|
||||
var actErr = await QDataServ.NumRequestErrors();
|
||||
answ.Add("errors", actErr);
|
||||
|
||||
var actDone = await QDataServ.NumRequestDone();
|
||||
answ.Add("done", actDone);
|
||||
return answ;
|
||||
@@ -88,6 +91,9 @@ namespace WebDoorCreator.API.Controllers
|
||||
var actProc = await QDataServ.RequestProcessing();
|
||||
answ.Add("processing", actProc);
|
||||
|
||||
var actErr = await QDataServ.RequestErr();
|
||||
answ.Add("errors", actErr);
|
||||
|
||||
var actDone = await QDataServ.RequestDone();
|
||||
answ.Add("done", actDone);
|
||||
return answ;
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace WebDoorCreator.Core
|
||||
// REDIS KEY Dati correnti x QueueMan
|
||||
public static readonly string LAST_CALC_REQ_KEY = $"{BASE_HASH}:Current:LastCalcReq";
|
||||
public static readonly string LAST_CALC_DONE_KEY = $"{BASE_HASH}:Current:LastCalcDone";
|
||||
public static readonly string CALC_REQ_ERRS = $"{BASE_HASH}:CalcRequests:Errors";
|
||||
public static readonly string CALC_REQ_PEND = $"{BASE_HASH}:CalcRequests:Pending";
|
||||
public static readonly string CALC_REQ_PROC = $"{BASE_HASH}:CalcRequests:Processing";
|
||||
public static readonly string CALC_REQ_DONE = $"{BASE_HASH}:CalcRequests:Completed";
|
||||
|
||||
@@ -102,6 +102,25 @@ namespace WebDoorCreator.Data.Services
|
||||
return numReq;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get # of calculation request with errors
|
||||
/// </summary>
|
||||
public async Task<long> NumRequestErrors()
|
||||
{
|
||||
long numReq = 0;
|
||||
string source = "REDIS";
|
||||
Dictionary<string, string> dictResult = new Dictionary<string, string>();
|
||||
// cerco da cache
|
||||
RedisKey currKey = new RedisKey(Constants.CALC_REQ_ERRS);
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
numReq = await redisDb.HashLengthAsync(currKey);
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"NumRequestErrors | {source} in: {ts.TotalMilliseconds} ms");
|
||||
return numReq;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get # of calculation request pending
|
||||
/// </summary>
|
||||
@@ -208,6 +227,56 @@ namespace WebDoorCreator.Data.Services
|
||||
return numReq;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Queue request with errors
|
||||
/// </summary>
|
||||
/// <returns>Dictionary of DoorId, saveVersNumb</returns>
|
||||
public async Task<Dictionary<string, string>> RequestErr()
|
||||
{
|
||||
string source = "REDIS";
|
||||
long numReq = 0;
|
||||
Dictionary<string, string> dictResult = new Dictionary<string, string>();
|
||||
// cerco da cache
|
||||
RedisKey currKey = new RedisKey(Constants.CALC_REQ_ERRS);
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
numReq = redisDb.HashLength(currKey);
|
||||
if (numReq > 0)
|
||||
{
|
||||
var rawData = await redisDb.HashGetAllAsync(currKey);
|
||||
foreach (var item in rawData)
|
||||
{
|
||||
dictResult.Add($"{item.Name}", $"{item.Value}");
|
||||
}
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"RequestErr | {source} in: {ts.TotalMilliseconds} ms");
|
||||
return dictResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rimuove hash record errori
|
||||
/// </summary>
|
||||
/// <returns>Dictionary of DoorId, saveVersNumb</returns>
|
||||
public async Task<bool> RequestErrRemove(string doorId)
|
||||
{
|
||||
RedisKey currKey = new RedisKey(Constants.CALC_REQ_ERRS);
|
||||
bool fatto = await RedHashRemove(currKey, doorId);
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Upsert record errori
|
||||
/// </summary>
|
||||
/// <returns>Dictionary of DoorId, saveVersNumb</returns>
|
||||
public async Task<long> RequestErrUpsert(string doorId, string vers)
|
||||
{
|
||||
RedisKey currKey = new RedisKey(Constants.CALC_REQ_ERRS);
|
||||
long numReq = await RedHashUpsert(currKey, doorId, vers);
|
||||
return numReq;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Queue request pending
|
||||
/// </summary>
|
||||
@@ -327,6 +396,15 @@ namespace WebDoorCreator.Data.Services
|
||||
await RequestProcessingRemove(item.Name!);
|
||||
fatto = true;
|
||||
}
|
||||
// cerco le richieste con errori
|
||||
currKey = new RedisKey(Constants.CALC_REQ_ERRS);
|
||||
rawData = await redisDb.HashGetAllAsync(currKey);
|
||||
foreach (var item in rawData)
|
||||
{
|
||||
await RequestPendingUpsert(item.Name!, item.Value!);
|
||||
await RequestErrRemove(item.Name!);
|
||||
fatto = true;
|
||||
}
|
||||
// cerco le richieste processed
|
||||
currKey = new RedisKey(Constants.CALC_REQ_DONE);
|
||||
rawData = await redisDb.HashGetAllAsync(currKey);
|
||||
@@ -357,22 +435,32 @@ namespace WebDoorCreator.Data.Services
|
||||
string sCurrVers = "";
|
||||
foreach (var calcTask in calcResults)
|
||||
{
|
||||
// solo se risultato valido...
|
||||
RedisKey currSvgKey = new RedisKey("");
|
||||
var doorData = calcTask.DoorIdVers.Split(".");
|
||||
sDoorId = doorData.Length > 0 ? doorData[0] : "";
|
||||
sCurrVers = doorData.Length > 0 ? doorData[1] : "";
|
||||
// se valido salvo SVG...
|
||||
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}");
|
||||
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
|
||||
// sposto tra le code
|
||||
await RequestProcessingRemove(sDoorId);
|
||||
await RequestDoneUpsert(sDoorId, sCurrVers);
|
||||
}
|
||||
// altrimenti salvo errore e metto in coda errori
|
||||
else
|
||||
{
|
||||
// salvo in area REDIS
|
||||
currSvgKey = new RedisKey($"{Constants.CALC_REQ_ERRS}:{sDoorId}:{sCurrVers}");
|
||||
await redisDb.StringSetAsync(currSvgKey, calcTask.ErrorMsg, DayLongCache);
|
||||
// sposto tra le 2 code
|
||||
await RequestProcessingRemove(sDoorId);
|
||||
await RequestErrUpsert(sDoorId, sCurrVers);
|
||||
}
|
||||
// invio il messaggio di ritorno...
|
||||
CalcDonePipe.saveAndSendMessage(Constants.LAST_CALC_DONE_KEY, calcTask.DoorIdVers);
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
@@ -425,30 +513,6 @@ namespace WebDoorCreator.Data.Services
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"SendCalcReq | DoorId: {DoorId} enqueued in: {ts.TotalMilliseconds} ms");
|
||||
|
||||
#if false
|
||||
// FIXME TODO!!!! levare quando ci sarà il vero sw in esecuzione...
|
||||
|
||||
// simulazione ritorno dati...
|
||||
string fileName = Path.Combine("temp", $"Logo{idxSim:00}.svg");
|
||||
if (File.Exists(fileName))
|
||||
{
|
||||
// update indici
|
||||
idxSim++;
|
||||
idxSim = idxSim % 4;
|
||||
// leggo file
|
||||
string svgCont = File.ReadAllText(fileName);
|
||||
// salvo in area REDIS
|
||||
RedisKey currSvgKey = new RedisKey($"{Constants.CALC_REQ_SVG_CACHE}:{sDoorId}:{sCurrVers}");
|
||||
await redisDb.StringSetAsync(currSvgKey, svgCont, DayLongCache);
|
||||
}
|
||||
// simulo attesa segnalazione messaggio porta calcolata
|
||||
await Task.Delay(300);
|
||||
string retMess = $"{sDoorId}:{sCurrVers}";
|
||||
// invio il FINTO messaggio di ritorno...
|
||||
CalcDonePipe.saveAndSendMessage(Constants.LAST_CALC_DONE_KEY, retMess);
|
||||
#endif
|
||||
|
||||
return currVers;
|
||||
}
|
||||
|
||||
@@ -458,13 +522,14 @@ namespace WebDoorCreator.Data.Services
|
||||
/// <returns>Dictionary of DoorId, saveVersNumb</returns>
|
||||
public async Task<Dictionary<string, string>> TakeProcessingItems(int numItems)
|
||||
{
|
||||
int maxTake = 10;
|
||||
int maxTake = Math.Min(10, numItems);
|
||||
long numReq = 0;
|
||||
Dictionary<string, string> dictResult = new Dictionary<string, string>();
|
||||
// cerco da cache
|
||||
RedisKey currKey = new RedisKey(Constants.CALC_REQ_PEND);
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
// calcolo il totale delle richieste pending
|
||||
numReq = redisDb.HashLength(currKey);
|
||||
if (numReq > 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user