File tree Expand file tree Collapse file tree 1 file changed +16
-4
lines changed
src/ServiceToolkit/src/SIL.ServiceToolkit/Services Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -22,12 +22,24 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
2222 . ToDictionary ( o => ( o . OutboxId , o . Method ) ) ;
2323 await ProcessMessagesAsync ( consumers , messages , stoppingToken ) ;
2424 using ISubscription < OutboxMessage > subscription = await messages . SubscribeAsync ( e => true , stoppingToken ) ;
25- while ( true )
25+ while ( ! stoppingToken . IsCancellationRequested )
2626 {
27- await subscription . WaitForChangeAsync ( cancellationToken : stoppingToken ) ;
28- if ( stoppingToken . IsCancellationRequested )
27+ try
28+ {
29+ await subscription . WaitForChangeAsync ( cancellationToken : stoppingToken ) ;
30+ stoppingToken . ThrowIfCancellationRequested ( ) ;
31+ await ProcessMessagesAsync ( consumers , messages , stoppingToken ) ;
32+ }
33+ catch ( TimeoutException e )
34+ {
35+ _logger . LogWarning ( e , "Change stream interrupted, trying again..." ) ;
36+ await Task . Delay ( TimeSpan . FromSeconds ( 10 ) , stoppingToken ) ;
37+ }
38+ catch ( OperationCanceledException e )
39+ {
40+ _logger . LogInformation ( e , "Cancellation requested, service is stopping..." ) ;
2941 break ;
30- await ProcessMessagesAsync ( consumers , messages , stoppingToken ) ;
42+ }
3143 }
3244 }
3345
You can’t perform that action at this time.
0 commit comments