Bilanciamento condizioni reload pagina intera:
- solo ogni 10 min - reset timers al cambio pagina
This commit is contained in:
@@ -61,24 +61,34 @@ namespace MP.SPEC.Components
|
||||
|
||||
public void ElapsedTimer(object? source, System.Timers.ElapsedEventArgs e)
|
||||
{
|
||||
if (!isLoading && LiveUpdate)
|
||||
// controlo se URL diverso da apgina params...
|
||||
if (!NavManager.Uri.Contains("PARAMS"))
|
||||
{
|
||||
aTimer.Stop();
|
||||
// inizio misura esecuzione
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
var pUpd = Task.Run(async () =>
|
||||
aTimer.Enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
aTimer.Enabled = true;
|
||||
if (!isLoading && LiveUpdate)
|
||||
{
|
||||
await Task.Delay(1);
|
||||
await InvokeAsync(() => reloadData(true));
|
||||
});
|
||||
pUpd.Wait();
|
||||
// misuro tempo esecuzione
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
int deltaTime = RefreshPeriod - (int)ts.TotalMilliseconds;
|
||||
aTimer.Interval = deltaTime > 100 ? deltaTime : 100;
|
||||
aTimer.Start();
|
||||
// inizio misura esecuzione
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
var pUpd = Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(1);
|
||||
await InvokeAsync(() => reloadData(true));
|
||||
});
|
||||
pUpd.Wait();
|
||||
// misuro tempo esecuzione
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
double deltaTime = RefreshPeriod - ts.TotalMilliseconds;
|
||||
// aggiungo fattore di disturbo random...
|
||||
double mFact = 0.01 * random.Next(80, 120);
|
||||
aTimer.Interval = mFact * (deltaTime > 100 ? deltaTime : 100);
|
||||
//aTimer.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +108,7 @@ namespace MP.SPEC.Components
|
||||
dataTo = (DateTime)SelDtMax;
|
||||
}
|
||||
|
||||
SearchRecords = await MDService.FluxLogGetLastFilt(dataTo, dataFrom, SelMacchina, SelFlux, MaxRecord, 1.1 * RefreshPeriod / 1000);
|
||||
SearchRecords = await MDService.FluxLogGetLastFilt(dataTo, dataFrom, SelMacchina, SelFlux, MaxRecord, RefreshPeriod / 1000);
|
||||
totalCount = SearchRecords.Count;
|
||||
ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList();
|
||||
await Task.Delay(1);
|
||||
@@ -114,6 +124,7 @@ namespace MP.SPEC.Components
|
||||
aTimer = new System.Timers.Timer(RefreshPeriod);
|
||||
aTimer.Elapsed += ElapsedTimer;
|
||||
aTimer.Enabled = true;
|
||||
aTimer.AutoReset = true;
|
||||
aTimer.Start();
|
||||
}
|
||||
|
||||
@@ -121,6 +132,8 @@ namespace MP.SPEC.Components
|
||||
|
||||
#region Protected Fields
|
||||
|
||||
protected Random random = new Random();
|
||||
|
||||
#endregion Protected Fields
|
||||
|
||||
#region Protected Properties
|
||||
@@ -195,10 +208,8 @@ namespace MP.SPEC.Components
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private System.Timers.Timer aTimer = null!;
|
||||
|
||||
private int _totalCount = 0;
|
||||
|
||||
private System.Timers.Timer aTimer = null!;
|
||||
private FluxLog? currRecord = null;
|
||||
|
||||
private List<FluxLog>? ListRecords;
|
||||
|
||||
@@ -575,6 +575,37 @@ namespace MP.SPEC.Data
|
||||
return await dbController.EvListInsert(newRec);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Imposta in redis la scadenza della pagina x il reload
|
||||
/// </summary>
|
||||
/// <param name="expTime"></param>
|
||||
/// <returns></returns>
|
||||
public DateTime ExpiryReloadParamGet()
|
||||
{
|
||||
DateTime dtRif = DateTime.Now;
|
||||
string currKey = $"{redisParamPageExp}";
|
||||
RedisValue rawData = redisDb.StringGet(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
dtRif = JsonConvert.DeserializeObject<DateTime>($"{rawData}");
|
||||
}
|
||||
return dtRif;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Imposta in redis la scadenza della pagina x il reload
|
||||
/// </summary>
|
||||
/// <param name="expTime"></param>
|
||||
/// <returns></returns>
|
||||
public bool ExpiryReloadParamSet(DateTime expTime)
|
||||
{
|
||||
bool fatto = false;
|
||||
string currKey = $"{redisParamPageExp}";
|
||||
string rawData = JsonConvert.SerializeObject(expTime);
|
||||
fatto = redisDb.StringSet(currKey, rawData);
|
||||
return fatto;
|
||||
}
|
||||
|
||||
public async Task<bool> FlushRedisCache()
|
||||
{
|
||||
await Task.Delay(1);
|
||||
@@ -1429,6 +1460,7 @@ namespace MP.SPEC.Data
|
||||
private const string redisOdlByBatch = redisXdlData + "OdlByBatch";
|
||||
private const string redisOdlCurrByMac = redisXdlData + "OdlByMac";
|
||||
private const string redisOdlList = redisXdlData + "OdlList";
|
||||
private const string redisParamPageExp = redisBaseAddrSpec + "Cache:ParamPage";
|
||||
private const string redisPOdlByOdl = redisXdlData + "POdlByOdl";
|
||||
private const string redisPOdlByPOdl = redisXdlData + "POdlByPOdl";
|
||||
private const string redisPOdlList = redisXdlData + "POdlList";
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<RootNamespace>MP.SPEC</RootNamespace>
|
||||
<Version>6.16.2212.1214</Version>
|
||||
<Version>6.16.2212.1220</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using MP.Data.DatabaseModels;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using MP.Data.DatabaseModels;
|
||||
using MP.SPEC.Components;
|
||||
using MP.SPEC.Data;
|
||||
using NLog;
|
||||
|
||||
namespace MP.SPEC.Pages
|
||||
{
|
||||
@@ -10,19 +12,70 @@ namespace MP.SPEC.Pages
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
aTimer.Elapsed -= ElapsedTimer;
|
||||
aTimer.Stop();
|
||||
aTimer.Close();
|
||||
aTimer.Dispose();
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
public void ElapsedTimer(object? source, System.Timers.ElapsedEventArgs e)
|
||||
{
|
||||
// controllo se sia scaduto tempo massimo (in redis) x ricaricare pagina in modo completo...
|
||||
var dtRif = MDService.ExpiryReloadParamGet();
|
||||
if (dtRif > DateTime.Now)
|
||||
{
|
||||
Log.Trace("----- Elapsed check PARAMS.cs -----");
|
||||
}
|
||||
else
|
||||
{
|
||||
var pUpd = Task.Run(async () =>
|
||||
{
|
||||
MDService.ExpiryReloadParamSet(DateTime.Now.AddSeconds(intForceReload));
|
||||
aTimer.Elapsed -= ElapsedTimer;
|
||||
aTimer.Stop();
|
||||
aTimer.Close();
|
||||
aTimer.Dispose();
|
||||
await Task.Delay(1);
|
||||
await InvokeAsync(() => forceReloadCache());
|
||||
});
|
||||
pUpd.Wait();
|
||||
}
|
||||
}
|
||||
|
||||
public void StartTimer()
|
||||
{
|
||||
Random random = new Random();
|
||||
double multPer = 0.01 * random.Next(50, 300);
|
||||
aTimer = new System.Timers.Timer(RefreshPeriod * multPer);
|
||||
aTimer.Elapsed += ElapsedTimer;
|
||||
aTimer.Enabled = true;
|
||||
aTimer.AutoReset = true;
|
||||
aTimer.Start();
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Protected Fields
|
||||
|
||||
protected int CurrCounter = 0;
|
||||
|
||||
protected int intForceReload = 600;
|
||||
protected DataPager? pagerODL = null!;
|
||||
|
||||
#endregion Protected Fields
|
||||
|
||||
#region Protected Properties
|
||||
|
||||
[Inject]
|
||||
protected MpDataService MDService { get; set; } = null!;
|
||||
|
||||
protected int RefreshPeriod
|
||||
{
|
||||
get => currFilter.TempoAgg;
|
||||
}
|
||||
|
||||
#endregion Protected Properties
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
protected async Task detailSel(FluxLog newRec)
|
||||
@@ -52,6 +105,19 @@ namespace MP.SPEC.Pages
|
||||
numRecord = newNum;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Esegue svuotamento forzato cache + reload pagina ogni minuto...
|
||||
/// </summary>
|
||||
protected async Task forceReloadCache()
|
||||
{
|
||||
Log.Debug("----- forceReloadCache on PARAMS.cs -----");
|
||||
await Task.Delay(1);
|
||||
await MDService.FlushRedisCache();
|
||||
await Task.Delay(1);
|
||||
// rimando a pagina corrente
|
||||
NavManager.NavigateTo(NavManager.Uri, true, true);
|
||||
}
|
||||
|
||||
protected void ForceReloadPage(int newNum)
|
||||
{
|
||||
currPage = newNum;
|
||||
@@ -76,6 +142,8 @@ namespace MP.SPEC.Pages
|
||||
modFilter.LiveUpdate = (currPage == 1);
|
||||
currFilter = modFilter;
|
||||
await Task.Delay(1);
|
||||
setExpiryReload();
|
||||
StartTimer();
|
||||
isFiltering = false;
|
||||
}
|
||||
|
||||
@@ -103,6 +171,13 @@ namespace MP.SPEC.Pages
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private System.Timers.Timer aTimer = null!;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Properties
|
||||
|
||||
private SelectFluxParams currFilter { get; set; } = new SelectFluxParams();
|
||||
@@ -114,8 +189,12 @@ namespace MP.SPEC.Pages
|
||||
}
|
||||
|
||||
private bool isFiltering { get; set; } = false;
|
||||
|
||||
private bool isLoading { get; set; } = true;
|
||||
|
||||
[Inject]
|
||||
private NavigationManager NavManager { get; set; } = null!;
|
||||
|
||||
private int numRecord
|
||||
{
|
||||
get => currFilter.NumRec;
|
||||
@@ -128,6 +207,16 @@ namespace MP.SPEC.Pages
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private void setExpiryReload()
|
||||
{
|
||||
// verifico se ho una scadenza expiry del periodo desiderato, sennò imposto nuova...
|
||||
var dtRif = MDService.ExpiryReloadParamGet();
|
||||
if (dtRif <= DateTime.Now)
|
||||
{
|
||||
MDService.ExpiryReloadParamSet(DateTime.Now.AddSeconds(intForceReload));
|
||||
}
|
||||
}
|
||||
|
||||
private async Task updateFilter(SelectFluxParams newParams)
|
||||
{
|
||||
isFiltering = false;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>Modulo MAPOSPEC </i>
|
||||
<h4>Versione: 6.16.2212.1214</h4>
|
||||
<h4>Versione: 6.16.2212.1220</h4>
|
||||
<br /> Note di rilascio:
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
@@ -1 +1 @@
|
||||
6.16.2212.1214
|
||||
6.16.2212.1220
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>6.16.2212.1214</version>
|
||||
<version>6.16.2212.1220</version>
|
||||
<url>https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/MP.SPEC.zip</url>
|
||||
<changelog>https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/ChangeLog.html</changelog>
|
||||
<mandatory>false</mandatory>
|
||||
|
||||
Reference in New Issue
Block a user