using AsbCloudApp.Services; using AsbCloudDb.Model; using AsbCloudInfrastructure.Services.DetectOperations; using AsbCloudInfrastructure.Services.Subsystems; using AsbCloudInfrastructure.Services; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using System; using System.Threading.Tasks; using System.Threading; namespace AsbCloudInfrastructure { public class Startup { public static void BeforeRunHandler(IHost host) { using var scope = host.Services.CreateScope(); var provider = scope.ServiceProvider; var context = provider.GetService(); context.Database.SetCommandTimeout(TimeSpan.FromSeconds(2 * 60)); context.Database.Migrate(); var wellService = provider.GetRequiredService(); wellService.EnshureTimezonesIsSetAsync(CancellationToken.None).Wait();// TODO: make this background work var backgroundWorker = provider.GetRequiredService(); backgroundWorker.Push(OperationDetectionWorkFactory.MakeWork()); backgroundWorker.Push(SubsystemOperationTimeCalcWorkFactory.MakeWork()); backgroundWorker.Push(LimitingParameterCalcWorkFactory.MakeWork()); Task.Delay(1_000) .ContinueWith(async (_) => await backgroundWorker.StartAsync(CancellationToken.None)); } } }