Fix chiamata program.cs x servizi scopet/singleton x flushDb
This commit is contained in:
+2
-2
@@ -64,9 +64,9 @@ builder.Services.AddSingleton<RouteStatsManager>();
|
||||
builder.Services.AddHostedService<MetricsFlushService>();
|
||||
|
||||
// da rivedere
|
||||
#if false
|
||||
builder.Services.AddHostedService<MetricsDbFlushService>();
|
||||
#if true
|
||||
#endif
|
||||
builder.Services.AddHostedService<MetricsDbFlushService>();
|
||||
|
||||
// MP.Data DbContext for Stats repositories
|
||||
string utilsConnString = builder.Configuration.GetConnectionString("MP.Utils") ?? "Server=localhost;Database=MoonPro_Utils; integrated security=True; MultipleActiveResultSets=True; App=MP.IOC;";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>Modulo MP-IOC </i>
|
||||
<h4>Versione: 6.16.2604.711</h4>
|
||||
<h4>Versione: 6.16.2604.712</h4>
|
||||
<br /> Note di rilascio:
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
@@ -1 +1 @@
|
||||
6.16.2604.711
|
||||
6.16.2604.712
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>6.16.2604.711</version>
|
||||
<version>6.16.2604.712</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>
|
||||
|
||||
@@ -8,24 +8,27 @@ namespace MP.IOC.Services
|
||||
{
|
||||
public class MetricsDbFlushService : BackgroundService
|
||||
{
|
||||
private readonly IServiceScopeFactory _scopeFactory;
|
||||
private const int FlushIntervalSeconds = 30;
|
||||
private readonly RouteStatsManager _stats;
|
||||
private readonly IStatsAggrService _aggrService;
|
||||
private readonly IStatsDetailService _detailService;
|
||||
//private readonly IStatsAggrService _aggrService;
|
||||
//private readonly IStatsDetailService _detailService;
|
||||
private readonly IConfiguration _config;
|
||||
private readonly IDatabase _db;
|
||||
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public MetricsDbFlushService(
|
||||
RouteStatsManager stats,
|
||||
IStatsAggrService aggrService,
|
||||
IStatsDetailService detailService,
|
||||
IServiceScopeFactory scopeFactory,
|
||||
//IStatsAggrService aggrService,
|
||||
//IStatsDetailService detailService,
|
||||
IConfiguration config,
|
||||
IConnectionMultiplexer mux)
|
||||
{
|
||||
_stats = stats;
|
||||
_aggrService = aggrService;
|
||||
_detailService = detailService;
|
||||
_scopeFactory = scopeFactory;
|
||||
//_aggrService = aggrService;
|
||||
//_detailService = detailService;
|
||||
_config = config;
|
||||
_db = mux.GetDatabase();
|
||||
}
|
||||
@@ -133,9 +136,10 @@ namespace MP.IOC.Services
|
||||
detailRecords.Add(detailRecord);
|
||||
}
|
||||
}
|
||||
|
||||
await using var scope = _scopeFactory.CreateAsyncScope();
|
||||
if (aggrRecords.Count > 0)
|
||||
{
|
||||
var _aggrService = scope.ServiceProvider.GetRequiredService<IStatsAggrService>();
|
||||
await _aggrService.UpsertManyAsync(aggrRecords, false);
|
||||
Log.Info("Flushed {count} current aggregated stats records", aggrRecords.Count);
|
||||
|
||||
@@ -150,6 +154,7 @@ namespace MP.IOC.Services
|
||||
|
||||
if (detailRecords.Count > 0)
|
||||
{
|
||||
var _detailService = scope.ServiceProvider.GetRequiredService<IStatsDetailService>();
|
||||
await _detailService.UpsertManyAsync(detailRecords, false);
|
||||
Log.Info("Flushed {count} current detail stats records", detailRecords.Count);
|
||||
|
||||
|
||||
@@ -70,7 +70,8 @@
|
||||
}
|
||||
},
|
||||
"RouteMan": {
|
||||
"FlushIntervalSeconds": 60,
|
||||
"FlushIntervalSeconds": 10,
|
||||
//"FlushIntervalSeconds": 60,
|
||||
"DefaultWeightOld": 100,
|
||||
"DefaultWeightNew": 0,
|
||||
"DeleteExpiredMetrics": false
|
||||
|
||||
Reference in New Issue
Block a user