Fix TelemetryTracker dbContext disposing.

This commit is contained in:
Фролов 2021-11-23 16:12:41 +05:00
parent 6412c24a3e
commit 3d8154ca2d

View File

@ -44,7 +44,7 @@ namespace AsbCloudInfrastructure.Services
var options = new DbContextOptionsBuilder<AsbCloudDbContext>()
.UseNpgsql(configuration.GetConnectionString("DefaultConnection"))
.Options;
using var db = new AsbCloudDbContext(options);
var db = new AsbCloudDbContext(options);
var cacheTelemetry = cacheDb.GetCachedTable<Telemetry>(db);
var keyValuePairs = new Dictionary<string, TrackerStat>(cacheTelemetry.Count());
@ -78,8 +78,6 @@ namespace AsbCloudInfrastructure.Services
.ToListAsync()
.ConfigureAwait(false);
db.Dispose();
var oldReqs = dates.Select(t => new
{
Uid = cacheTelemetry.FirstOrDefault(c => c.Id == t.IdTelemetry)?.RemoteUid,
@ -94,6 +92,10 @@ namespace AsbCloudInfrastructure.Services
telemetryStat.TelemetryDateMax = oldReq.DateMax;
telemetryStat.LastTimeServer = oldReq.DateMax;
}
}).ContinueWith((t) =>
{
db.Dispose();
return t;
});
}