2022-07-18 18:51:49 +05:00
|
|
|
|
using AsbCloudDb.Model;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
2022-07-14 03:47:11 +05:00
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2022-07-18 18:51:49 +05:00
|
|
|
|
using System.Diagnostics;
|
2022-07-14 03:47:11 +05:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudInfrastructure.Services.Subsystems
|
|
|
|
|
{
|
|
|
|
|
internal class SubsystemOperationTimeBackgroundService : BackgroundService
|
|
|
|
|
{
|
|
|
|
|
private readonly string connectionString;
|
|
|
|
|
public SubsystemOperationTimeBackgroundService(IConfiguration configuration)
|
|
|
|
|
{
|
|
|
|
|
connectionString = configuration.GetConnectionString("DefaultConnection");
|
|
|
|
|
}
|
2022-07-18 18:51:49 +05:00
|
|
|
|
protected override async Task ExecuteAsync(CancellationToken token)
|
2022-07-14 03:47:11 +05:00
|
|
|
|
{
|
2022-07-18 18:51:49 +05:00
|
|
|
|
var timeToStartAnalysis = DateTime.Now;
|
|
|
|
|
var options = new DbContextOptionsBuilder<AsbCloudDbContext>()
|
|
|
|
|
.UseNpgsql(connectionString)
|
|
|
|
|
.Options;
|
|
|
|
|
|
|
|
|
|
while (!token.IsCancellationRequested)
|
|
|
|
|
{
|
|
|
|
|
if (DateTime.Now > timeToStartAnalysis)
|
|
|
|
|
{
|
|
|
|
|
timeToStartAnalysis = DateTime.Now + TimeSpan.FromHours(1);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Trace.TraceError(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
//GC.Collect();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var ms = (int)(timeToStartAnalysis - DateTime.Now).TotalMilliseconds;
|
|
|
|
|
ms = ms > 100 ? ms : 100;
|
|
|
|
|
await Task.Delay(ms, token).ConfigureAwait(false);
|
|
|
|
|
}
|
2022-07-14 03:47:11 +05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|