stop application if worker fails

This commit is contained in:
Nicolas Constant 2021-02-13 21:17:48 -05:00
parent 9bdca4e202
commit 30bd16447f
No known key found for this signature in database
GPG key ID: 1E9F677FB01A5688

View file

@ -13,19 +13,28 @@ namespace BirdsiteLive.Services
{
private readonly IDatabaseInitializer _databaseInitializer;
private readonly IStatusPublicationPipeline _statusPublicationPipeline;
private readonly IHostApplicationLifetime _applicationLifetime;
#region Ctor
public FederationService(IDatabaseInitializer databaseInitializer, IStatusPublicationPipeline statusPublicationPipeline)
public FederationService(IDatabaseInitializer databaseInitializer, IStatusPublicationPipeline statusPublicationPipeline, IHostApplicationLifetime applicationLifetime)
{
_databaseInitializer = databaseInitializer;
_statusPublicationPipeline = statusPublicationPipeline;
_applicationLifetime = applicationLifetime;
}
#endregion
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
await _databaseInitializer.InitAndMigrateDbAsync();
await _statusPublicationPipeline.ExecuteAsync(stoppingToken);
try
{
await _databaseInitializer.InitAndMigrateDbAsync();
await _statusPublicationPipeline.ExecuteAsync(stoppingToken);
}
finally
{
_applicationLifetime.StopApplication();
}
}
}
}