modifica da testare x gestione numRev calcolo
This commit is contained in:
@@ -45,6 +45,24 @@ namespace WebDoorCreator.API.Controllers
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cleanup dati delle code di calcolo
|
||||
/// </summary>
|
||||
/// <param name="passPhrase">Chiave x auth di reset</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("DCCacheCleanup")]
|
||||
public async Task<string> DCCacheCleanup(string passPhrase)
|
||||
{
|
||||
string answ = "NA";
|
||||
bool fatto = false;
|
||||
if (passPhrase == "bbbBirdIsTheWord")
|
||||
{
|
||||
fatto = await QDataServ.DoorCalcCacheCleanup();
|
||||
}
|
||||
answ = fatto ? "OK" : "NO";
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset delle code di chiamata x ripetere simulazione
|
||||
/// </summary>
|
||||
|
||||
@@ -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 LAST_DOOR_REFR_KEY = $"{BASE_HASH}:Current:LastDoorRefr";
|
||||
public static readonly string CALC_REQ_DONE = $"{BASE_HASH}:CalcRequests:Completed";
|
||||
public static readonly string CALC_REQ_ERRS = $"{BASE_HASH}:CalcRequests:Errors";
|
||||
public static readonly string CALC_REQ_PEND = $"{BASE_HASH}:CalcRequests:Pending";
|
||||
|
||||
@@ -63,6 +63,62 @@ namespace WebDoorCreator.Data.Services
|
||||
redisConn.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua pulizia cache dati calcolo porte
|
||||
/// </summary>
|
||||
/// <param name="DoorId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> DoorCalcCacheCleanup()
|
||||
{
|
||||
/*----------------------------------
|
||||
* Recupero Rev corrente porta o inizializza cercando
|
||||
* - coda calcoli pending
|
||||
* - coda errori
|
||||
* - coda calcoli eseguiti
|
||||
*
|
||||
* se non trova riparte da 1
|
||||
*
|
||||
----------------------------------*/
|
||||
bool fatto = false;
|
||||
int numDayPre = 30;
|
||||
if (!string.IsNullOrEmpty(_configuration.GetValue<string>("RumtimeOpt:MaxDayCalcCache")))
|
||||
{
|
||||
numDayPre = _configuration.GetValue<int>("RumtimeOpt:MaxDayCalcCache");
|
||||
}
|
||||
DateTime dtLimite = DateTime.Now.AddDays(-numDayPre);
|
||||
// recupero elenco di tutti i refresh porte...
|
||||
var refreshStatus = await DoorRefreshStatus();
|
||||
// ciclo su tutti e cerco quelli + vecchi di x giorni
|
||||
if (refreshStatus != null && refreshStatus.Count > 0)
|
||||
{
|
||||
DateTime dtCurr = DateTime.Now;
|
||||
foreach (var item in refreshStatus)
|
||||
{
|
||||
// confronto data-ora della singola porta...
|
||||
if (!string.IsNullOrEmpty(item.Key))
|
||||
{
|
||||
try
|
||||
{
|
||||
var rawDate = JsonConvert.DeserializeObject<DateTime>(item.Value);
|
||||
// se esiste e SE è scaduto
|
||||
if (rawDate > DateTime.MinValue && rawDate < dtLimite)
|
||||
{
|
||||
// cancello i dati!
|
||||
await RequestProcessingRemove(item.Key);
|
||||
await RequestErrRemove(item.Key);
|
||||
await RequestDoneRemove(item.Key);
|
||||
await DoorRefreshRemove(item.Key);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
}
|
||||
}
|
||||
await Task.Delay(1);
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restitusice gli errori della porta in oggetto
|
||||
/// </summary>
|
||||
@@ -94,6 +150,58 @@ namespace WebDoorCreator.Data.Services
|
||||
return errVal.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove for single hash record
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> DoorRefreshRemove(string doorId)
|
||||
{
|
||||
RedisKey currKey = new RedisKey(Constants.LAST_DOOR_REFR_KEY);
|
||||
bool fatto = await RedHashRemove(currKey, doorId);
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Door (last) Refresh status
|
||||
/// </summary>
|
||||
/// <returns>Dictionary of DoorId, saveVersNumb</returns>
|
||||
public async Task<Dictionary<string, string>> DoorRefreshStatus()
|
||||
{
|
||||
string source = "REDIS";
|
||||
long numReq = 0;
|
||||
Dictionary<string, string> dictResult = new Dictionary<string, string>();
|
||||
// cerco da cache
|
||||
RedisKey currKey = new RedisKey(Constants.LAST_DOOR_REFR_KEY);
|
||||
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($"DoorRefreshStatus | {source} in: {ts.TotalMilliseconds} ms");
|
||||
return dictResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Upsert info ultimo update di una porta
|
||||
/// </summary>
|
||||
/// <returns>Dictionary of DoorId, saveVersNumb</returns>
|
||||
public async Task<long> DoorRefreshUpsert(string doorId)
|
||||
{
|
||||
DateTime adesso = DateTime.Now;
|
||||
string sAdesso = JsonConvert.SerializeObject(adesso);
|
||||
RedisKey currKey = new RedisKey(Constants.LAST_DOOR_REFR_KEY);
|
||||
long numReq = await RedHashUpsert(currKey, doorId, sAdesso);
|
||||
return numReq;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restitusice l'SVG della porta in oggetto
|
||||
/// </summary>
|
||||
@@ -190,23 +298,6 @@ namespace WebDoorCreator.Data.Services
|
||||
return numReq;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove for single hash record
|
||||
/// </summary>
|
||||
/// <param name="currKey">Chiave redis della Hashlist</param>
|
||||
/// <param name="chiave">Chiave nella HashList</param>
|
||||
/// <returns>Esito rimozione</returns>
|
||||
public async Task<bool> RedHashRemove(RedisKey currKey, string chiave)
|
||||
{
|
||||
bool fatto = false;
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
fatto = await redisDb.HashDeleteAsync(currKey, chiave);
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"RedHashRemove | {currKey} | in: {ts.TotalMilliseconds} ms");
|
||||
return fatto;
|
||||
}
|
||||
/// <summary>
|
||||
/// Verify existence for single hash record
|
||||
/// </summary>
|
||||
@@ -233,6 +324,24 @@ namespace WebDoorCreator.Data.Services
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove for single hash record
|
||||
/// </summary>
|
||||
/// <param name="currKey">Chiave redis della Hashlist</param>
|
||||
/// <param name="chiave">Chiave nella HashList</param>
|
||||
/// <returns>Esito rimozione</returns>
|
||||
public async Task<bool> RedHashRemove(RedisKey currKey, string chiave)
|
||||
{
|
||||
bool fatto = false;
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
fatto = await redisDb.HashDeleteAsync(currKey, chiave);
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"RedHashRemove | {currKey} | in: {ts.TotalMilliseconds} ms");
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Queue request done
|
||||
/// </summary>
|
||||
@@ -534,33 +643,12 @@ namespace WebDoorCreator.Data.Services
|
||||
/// <returns>indice/versione del calcolo DDF</returns>
|
||||
public async Task<int> SendCalcReq(int DoorId, string FullDDF)
|
||||
{
|
||||
int currVers = 1;
|
||||
string sDoorId = $"{DoorId}";
|
||||
string sCurrVers = "";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
|
||||
// per prima cosa controllo se ho GIA' in coda qualcosa come richieste
|
||||
long numPending = await NumRequestPending();
|
||||
|
||||
// se coda non vuota: cerco la DoorId corrente, se c'è sovrascrivo versione altrimenti
|
||||
if (numPending != 0)
|
||||
{
|
||||
var currPending = await RequestPending();
|
||||
if (currPending != null)
|
||||
{
|
||||
if (currPending.ContainsKey(sDoorId))
|
||||
{
|
||||
sCurrVers = currPending[sDoorId];
|
||||
int.TryParse(sCurrVers, out currVers);
|
||||
currVers++;
|
||||
}
|
||||
}
|
||||
}
|
||||
sCurrVers = $"{currVers}";
|
||||
// inserisco in coda
|
||||
numPending = await RequestPendingUpsert(sDoorId, sCurrVers);
|
||||
// elimino da code errori
|
||||
string sDoorId = $"{DoorId}";
|
||||
int currVers = await DoorCalcRev(sDoorId);
|
||||
string sCurrVers = $"{currVers}";
|
||||
// elimino da code errori (SE fosse presente)
|
||||
await RequestErrRemove(sDoorId);
|
||||
|
||||
// salvo nell'archivio REDIS delle porte il DDF corrente (key=doorId.versNumb), potrebbe
|
||||
@@ -569,7 +657,7 @@ namespace WebDoorCreator.Data.Services
|
||||
await redisDb.StringSetAsync(currDdfKey, FullDDF, DayLongCache);
|
||||
|
||||
// invio sul canale dei messaggi il numero di items in coda attuali x chiedere esecuzione...
|
||||
numPending = await NumRequestPending();
|
||||
long numPending = await NumRequestPending();
|
||||
bool answ = CalcReqPipe.saveAndSendMessage(Constants.LAST_CALC_REQ_KEY, $"{numPending}");
|
||||
|
||||
stopWatch.Stop();
|
||||
@@ -628,8 +716,6 @@ namespace WebDoorCreator.Data.Services
|
||||
return dictResult;
|
||||
}
|
||||
|
||||
protected static bool queueLock { get; set; } = false;
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Protected Fields
|
||||
@@ -651,8 +737,81 @@ namespace WebDoorCreator.Data.Services
|
||||
|
||||
#endregion Protected Fields
|
||||
|
||||
#region Protected Properties
|
||||
|
||||
protected static bool queueLock { get; set; } = false;
|
||||
|
||||
#endregion Protected Properties
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
/// <summary>
|
||||
/// Recupera revisione corrente della porta o inizializza
|
||||
/// </summary>
|
||||
/// <param name="DoorId"></param>
|
||||
/// <returns></returns>
|
||||
protected async Task<int> DoorCalcRev(string sDoorId)
|
||||
{
|
||||
/*----------------------------------
|
||||
* Recupero Rev corrente porta o inizializza cercando
|
||||
* - coda calcoli pending
|
||||
* - coda errori
|
||||
* - coda calcoli eseguiti
|
||||
*
|
||||
* se non trova riparte da 1
|
||||
*
|
||||
----------------------------------*/
|
||||
int currVers = 1;
|
||||
string sCurrVers = "";
|
||||
// per prima cosa controllo se ho GIA' in coda qualcosa come richieste
|
||||
if (await NumRequestPending() > 0)
|
||||
{
|
||||
var currPending = await RequestPending();
|
||||
if (currPending != null)
|
||||
{
|
||||
if (currPending.ContainsKey(sDoorId))
|
||||
{
|
||||
sCurrVers = currPending[sDoorId];
|
||||
int.TryParse(sCurrVers, out currVers);
|
||||
currVers++;
|
||||
}
|
||||
}
|
||||
}
|
||||
// cerco coda errori
|
||||
if (await NumRequestErrors() > 0)
|
||||
{
|
||||
var currErrors = await RequestErr();
|
||||
if (currErrors != null)
|
||||
{
|
||||
if (currErrors.ContainsKey(sDoorId))
|
||||
{
|
||||
sCurrVers = currErrors[sDoorId];
|
||||
int.TryParse(sCurrVers, out currVers);
|
||||
currVers++;
|
||||
}
|
||||
}
|
||||
}
|
||||
// cerco coda task completati
|
||||
if (await NumRequestDone() > 0)
|
||||
{
|
||||
var currDone = await RequestDone();
|
||||
if (currDone != null)
|
||||
{
|
||||
if (currDone.ContainsKey(sDoorId))
|
||||
{
|
||||
sCurrVers = currDone[sDoorId];
|
||||
int.TryParse(sCurrVers, out currVers);
|
||||
currVers++;
|
||||
}
|
||||
}
|
||||
}
|
||||
// inserisco in coda x calcoli
|
||||
await RequestPendingUpsert(sDoorId, $"{currVers}");
|
||||
// metto in coda "last calc" la porta corrente x pulizia successiva
|
||||
await DoorRefreshUpsert(sDoorId);
|
||||
return currVers;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupero chiave da redis
|
||||
/// </summary>
|
||||
|
||||
@@ -27,6 +27,9 @@
|
||||
"DisableIdentMigrate": true,
|
||||
"DisableWDCMigrate": true
|
||||
},
|
||||
"RumtimeOpt": {
|
||||
"MaxDayCalcCache": 7
|
||||
},
|
||||
"ConfDDF": {
|
||||
"Header": [
|
||||
"#WEBDOORCREATOR",
|
||||
|
||||
Reference in New Issue
Block a user