@@ -18,6 +18,7 @@ public class RepairBuildingService : BackgroundService
1818 private readonly ITicketing _ticketing ;
1919 private readonly ProjectionRepository _projectionRepository ;
2020 private readonly INotificationService _notificationService ;
21+ private readonly IHostApplicationLifetime _hostApplicationLifetime ;
2122 private readonly ILogger < RepairBuildingService > _logger ;
2223
2324 public RepairBuildingService (
@@ -26,13 +27,15 @@ public RepairBuildingService(
2627 ITicketing ticketing ,
2728 ProjectionRepository projectionRepository ,
2829 INotificationService notificationService ,
30+ IHostApplicationLifetime hostApplicationLifetime ,
2931 ILoggerFactory loggerFactory )
3032 {
3133 _sqsRateLimiter = sqsRateLimiter ;
3234 _repairBuildingRepository = repairBuildingRepository ;
3335 _ticketing = ticketing ;
3436 _projectionRepository = projectionRepository ;
3537 _notificationService = notificationService ;
38+ _hostApplicationLifetime = hostApplicationLifetime ;
3639 _logger = loggerFactory . CreateLogger < RepairBuildingService > ( ) ;
3740 }
3841
@@ -62,11 +65,13 @@ await _sqsRateLimiter.Handle<int>(
6265 stoppingToken ) ;
6366
6467 _logger . LogInformation ( "Building repair processing completed." ) ;
68+
69+ _hostApplicationLifetime . StopApplication ( ) ;
6570 }
6671
6772 private async Task WaitIfProducerProjectionBehindAsync ( CancellationToken cancellationToken )
6873 {
69- while ( true )
74+ while ( ! cancellationToken . IsCancellationRequested )
7075 {
7176 var producerPosition = await _projectionRepository . GetProducerPosition ( ) ;
7277 var headPosition = await _projectionRepository . GetMaxAllStreamPosition ( ) ;
0 commit comments