forked from ddrilling/AsbCloudServer
39 lines
1.5 KiB
C#
39 lines
1.5 KiB
C#
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<IAsbCloudDbContext>();
|
|
context.Database.SetCommandTimeout(TimeSpan.FromSeconds(2 * 60));
|
|
context.Database.Migrate();
|
|
|
|
var wellService = provider.GetRequiredService<IWellService>();
|
|
wellService.EnshureTimezonesIsSetAsync(CancellationToken.None).Wait();// TODO: make this background work
|
|
|
|
var backgroundWorker = provider.GetRequiredService<Background.BackgroundWorker>();
|
|
backgroundWorker.Push(OperationDetectionWorkFactory.MakeWork());
|
|
backgroundWorker.Push(SubsystemOperationTimeCalcWorkFactory.MakeWork());
|
|
backgroundWorker.Push(LimitingParameterCalcWorkFactory.MakeWork());
|
|
|
|
Task.Delay(1_000)
|
|
.ContinueWith(async (_) => await backgroundWorker.StartAsync(CancellationToken.None));
|
|
}
|
|
}
|
|
}
|