BirdsiteLive/src/BirdsiteLive/Services/FederationService.cs

40 lines
1.3 KiB
C#
Raw Normal View History

2020-07-07 07:33:52 +02:00
using System;
2021-01-23 02:17:22 +01:00
using System.Linq;
2020-07-07 07:33:52 +02:00
using System.Threading;
using System.Threading.Tasks;
2021-01-23 02:17:22 +01:00
using BirdsiteLive.DAL;
2020-07-08 03:03:20 +02:00
using BirdsiteLive.DAL.Contracts;
2020-07-16 07:19:41 +02:00
using BirdsiteLive.Pipeline;
2020-07-07 07:33:52 +02:00
using Microsoft.Extensions.Hosting;
namespace BirdsiteLive.Services
{
public class FederationService : BackgroundService
{
2021-01-23 02:17:22 +01:00
private readonly IDatabaseInitializer _databaseInitializer;
2020-07-16 07:19:41 +02:00
private readonly IStatusPublicationPipeline _statusPublicationPipeline;
2021-02-14 03:17:48 +01:00
private readonly IHostApplicationLifetime _applicationLifetime;
2020-07-07 07:33:52 +02:00
#region Ctor
2021-02-14 03:17:48 +01:00
public FederationService(IDatabaseInitializer databaseInitializer, IStatusPublicationPipeline statusPublicationPipeline, IHostApplicationLifetime applicationLifetime)
2020-07-07 07:33:52 +02:00
{
2021-01-23 02:17:22 +01:00
_databaseInitializer = databaseInitializer;
2020-07-16 07:19:41 +02:00
_statusPublicationPipeline = statusPublicationPipeline;
2021-02-14 03:17:48 +01:00
_applicationLifetime = applicationLifetime;
2020-07-07 07:33:52 +02:00
}
#endregion
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
2021-02-14 03:17:48 +01:00
try
{
await _databaseInitializer.InitAndMigrateDbAsync();
await _statusPublicationPipeline.ExecuteAsync(stoppingToken);
}
finally
{
_applicationLifetime.StopApplication();
}
2020-07-07 07:33:52 +02:00
}
}
}