Fix RIOC x scadenza chiavi hour
This commit is contained in:
@@ -368,8 +368,8 @@ namespace MP.Data.Services
|
||||
var cacheOptions = new FusionCacheEntryOptions()
|
||||
.SetDuration(expiration)
|
||||
.SetFailSafe(true);
|
||||
// cache in RAM per 1/3 del tempo x risparmiare risorse
|
||||
cacheOptions.MemoryCacheDuration = expiration / 3;
|
||||
// cache in RAM per 1/2 del tempo x risparmiare risorse
|
||||
cacheOptions.MemoryCacheDuration = expiration / 2;
|
||||
|
||||
var final = await _cache.GetOrSetAsync<T>(
|
||||
cacheKey,
|
||||
|
||||
@@ -91,6 +91,19 @@ namespace MP.Data.Services.IOC
|
||||
/// <inheritdoc />
|
||||
public async Task<string> GetCurrOdlAsync(string idxMacchina)
|
||||
{
|
||||
string cKey = $"{MP.Data.Utils.redisOdlCurrByMac}:{idxMacchina}";
|
||||
return await GetOrFetchAsync(
|
||||
operationName: "GetCurrOdlAsync",
|
||||
cacheKey: cKey,
|
||||
fetchFunc: async () =>
|
||||
{
|
||||
return await GetCurrOdlByProdAsync(idxMacchina);
|
||||
},
|
||||
expiration: GetRandTOut(redisShortTimeCache),
|
||||
tagList: ["IOC_CurrOdl", cKey, idxMacchina]
|
||||
);
|
||||
|
||||
#if false
|
||||
string result = "";
|
||||
string currKey = $"{MP.Data.Utils.redisOdlCurrByMac}:{idxMacchina}";
|
||||
// cerco in redis dato valOut sel macchina...
|
||||
@@ -104,7 +117,8 @@ namespace MP.Data.Services.IOC
|
||||
result = await GetCurrOdlByProdAsync(idxMacchina);
|
||||
_redisDb.StringSet(currKey, result, GetRandTOut(redisShortTimeCache));
|
||||
}
|
||||
return result;
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -117,39 +131,27 @@ namespace MP.Data.Services.IOC
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> IobInsEnabAsync(string idxMacchina)
|
||||
{
|
||||
#if false
|
||||
string cacheKey = $"IOC_IobInsEnab_{idxMacchina}";
|
||||
return await GetOrFetchAsync(cacheKey, async () =>
|
||||
{
|
||||
var rKey = MP.Data.Utils.RedKeyDatiMacc(idxMacchina, MpIoNS);
|
||||
|
||||
string? val = await _redisDb.HashGetAsync(rKey, "insEnabled");
|
||||
|
||||
if (val == null)
|
||||
string cKey = $"IOC_IobInsEnab_{idxMacchina}";
|
||||
return await GetOrFetchAsync(
|
||||
operationName: "StatoProdMacchinaAsync",
|
||||
cacheKey: cKey,
|
||||
fetchFunc: async () =>
|
||||
{
|
||||
var data = await ResetDatiMacchinaAsync(idxMacchina);
|
||||
data.TryGetValue("insEnabled", out val);
|
||||
}
|
||||
var rKey = MP.Data.Utils.RedKeyDatiMacc(idxMacchina, MpIoNS);
|
||||
|
||||
return val != null && (val == "1" || val.ToLower() == "true");
|
||||
}, TimeSpan.FromSeconds(5));
|
||||
#endif
|
||||
string? val = await _redisDb.HashGetAsync(rKey, "insEnabled");
|
||||
|
||||
bool answ = false;
|
||||
// ORA recupero da memoria redis...
|
||||
var rKey = MP.Data.Utils.RedKeyDatiMacc(idxMacchina, MpIoNS);
|
||||
RedisValue rawData = await _redisDb.HashGetAsync(rKey, (RedisValue)"insEnabled");
|
||||
// se è vuoto... leggo da DB e popolo!
|
||||
if (!rawData.HasValue)
|
||||
{
|
||||
await ResetDatiMacchinaAsync(idxMacchina);
|
||||
// riprovo
|
||||
rawData = await _redisDb.HashGetAsync(rKey, (RedisValue)"insEnabled");
|
||||
}
|
||||
if (val == null)
|
||||
{
|
||||
var data = await ResetDatiMacchinaAsync(idxMacchina);
|
||||
data.TryGetValue("insEnabled", out val);
|
||||
}
|
||||
|
||||
// provo conversione
|
||||
bool.TryParse($"{rawData}", out answ);
|
||||
return answ;
|
||||
return val != null && (val == "1" || val.ToLower() == "true");
|
||||
},
|
||||
expiration: GetRandTOut(30),
|
||||
tagList: ["IOC_IobInsEnab", cKey, idxMacchina]
|
||||
);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -886,6 +888,8 @@ namespace MP.Data.Services.IOC
|
||||
// Eseguiamo tutto in un unico viaggio verso Redis
|
||||
bool success = await transaction.ExecuteAsync();
|
||||
|
||||
await ForceFlushFusionCacheAsync(idxMacc);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1040,13 +1044,13 @@ namespace MP.Data.Services.IOC
|
||||
/// <returns></returns>
|
||||
private async Task<StatoProdModel> StatoProdMacchinaAsync(string idxMacchina, DateTime dtReq, bool forceDb = false)
|
||||
{
|
||||
string cKey = $"IOC_StatoProd_{idxMacchina}";
|
||||
var stdTTL = TimeSpan.FromSeconds(30);
|
||||
string cKey = $"{MP.Data.Utils.redisStatoProd}:{idxMacchina}:{dtReq:HHmm}";
|
||||
return await GetOrFetchAsync(
|
||||
operationName: "StatoProdMacchinaAsync",
|
||||
cacheKey: cKey,
|
||||
fetchFunc: async () =>
|
||||
{
|
||||
#if false
|
||||
StatoProdModel? result = new StatoProdModel();
|
||||
// cerco in _redisConn...
|
||||
string currKey = $"{MP.Data.Utils.redisStatoProd}:{idxMacchina}:{dtReq:HHmm}";
|
||||
@@ -1066,9 +1070,11 @@ namespace MP.Data.Services.IOC
|
||||
{
|
||||
result = new StatoProdModel();
|
||||
}
|
||||
return result;
|
||||
return result;
|
||||
#endif
|
||||
return await _repo.StatoProdMacchinaAsync(idxMacchina, dtReq);
|
||||
},
|
||||
expiration: stdTTL,
|
||||
expiration: GetRandTOut(30),
|
||||
tagList: ["IOC_StatoProd", cKey, idxMacchina]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Version>8.16.2606.1117</Version>
|
||||
<Version>8.16.2606.1118</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>Modulo MP-IOC </i>
|
||||
<h4>Versione: 8.16.2606.1117</h4>
|
||||
<h4>Versione: 8.16.2606.1118</h4>
|
||||
<br /> Note di rilascio:
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
@@ -1 +1 @@
|
||||
8.16.2606.1117
|
||||
8.16.2606.1118
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>8.16.2606.1117</version>
|
||||
<version>8.16.2606.1118</version>
|
||||
<url>https://nexus.steamware.net/repository/SWS/MP-IOC/stable/LAST/MP.IOC.zip</url>
|
||||
<changelog>https://nexus.steamware.net/repository/SWS/MP-IOC/stable/LAST/ChangeLog.html</changelog>
|
||||
<mandatory>false</mandatory>
|
||||
|
||||
@@ -165,9 +165,19 @@ namespace MP.RIOC.Services
|
||||
var sKey = (RedisKey)$"{statKey}";
|
||||
if (!TryParseKeyMetadata(sKey, out var meta) || meta.IsHourType) continue;
|
||||
|
||||
// Verifica se la chiave è "orfana" (nessun TTL o TTL troppo lungo >30gg)
|
||||
// Verifica se la chiave è "orfana"
|
||||
bool isOrphanKey = false;
|
||||
var keyTtl = GetKeyTtl(sKey);
|
||||
bool isOrphanKey = keyTtl?.TotalSeconds < 0 || keyTtl?.TotalHours > 30.25 * 24;
|
||||
if (keyTtl == null)
|
||||
{
|
||||
// Nessun TTL recuperato = chiave senza scadenza = orfana se > 30 gg
|
||||
DateTime cutoffDay = DateTime.Today.AddDays(-30);
|
||||
isOrphanKey = meta.Timestamp < cutoffDay;
|
||||
}
|
||||
else
|
||||
{
|
||||
isOrphanKey = keyTtl.Value.TotalSeconds < 0 || keyTtl.Value.TotalHours > 30.25 * 24;
|
||||
}
|
||||
|
||||
// Se era scaduta o orfana e abbiamo il permesso, segnamola per la cancellazione
|
||||
if ((meta.Timestamp < currentDayStart || isOrphanKey) && deleteConfirmed)
|
||||
@@ -299,9 +309,19 @@ namespace MP.RIOC.Services
|
||||
var sKey = (RedisKey)$"{statKey}";
|
||||
if (!TryParseKeyMetadata(sKey, out var meta) || !meta.IsHourType) continue;
|
||||
|
||||
// Verifica se la chiave è "orfana" (nessun TTL o TTL troppo lungo >15gg)
|
||||
// Verifica se la chiave è "orfana"
|
||||
bool isOrphanKey = false;
|
||||
var keyTtl = GetKeyTtl(sKey);
|
||||
bool isOrphanKey = keyTtl?.TotalSeconds < 0 || keyTtl?.TotalHours > 15.25 * 24;
|
||||
if (keyTtl == null)
|
||||
{
|
||||
// Nessun TTL recuperato = chiave senza scadenza = orfana se > 7 gg
|
||||
DateTime cutoffHour = DateTime.Now.AddDays(-7);
|
||||
isOrphanKey = meta.Timestamp < cutoffHour;
|
||||
}
|
||||
else
|
||||
{
|
||||
isOrphanKey = keyTtl.Value.TotalSeconds < 0 || keyTtl.Value.TotalHours > 15.25 * 24;
|
||||
}
|
||||
|
||||
// Se era scaduta o orfana e abbiamo il permesso, segnamola per la cancellazione
|
||||
if ((meta.Timestamp < currentHourStart || isOrphanKey) && deleteConfirmed)
|
||||
|
||||
Reference in New Issue
Block a user