|
|
|
@ -28,11 +28,18 @@ public class WorkerService : BackgroundService |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected override async Task ExecuteAsync(CancellationToken cancellationToken) |
|
|
|
protected override async Task ExecuteAsync(CancellationToken cancellationToken) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
_logger.LogInformation("Worker service started"); |
|
|
|
_logger.LogInformation("Worker service started"); |
|
|
|
|
|
|
|
|
|
|
|
await foreach (IBackgroundServiceRequest request in _channel.ReadAllAsync(cancellationToken)) |
|
|
|
await foreach (IBackgroundServiceRequest request in _channel.ReadAllAsync(cancellationToken)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (cancellationToken.IsCancellationRequested) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
using IServiceScope scope = _serviceScopeFactory.CreateScope(); |
|
|
|
using IServiceScope scope = _serviceScopeFactory.CreateScope(); |
|
|
|
|
|
|
|
|
|
|
|
try |
|
|
|
try |
|
|
|
@ -83,6 +90,10 @@ public class WorkerService : BackgroundService |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
catch (ObjectDisposedException) when (cancellationToken.IsCancellationRequested) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// this can happen when we're shutting down
|
|
|
|
|
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
{ |
|
|
|
_logger.LogWarning(ex, "Failed to process background service request"); |
|
|
|
_logger.LogWarning(ex, "Failed to process background service request"); |
|
|
|
@ -99,4 +110,9 @@ public class WorkerService : BackgroundService |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception ex) when (ex is TaskCanceledException or OperationCanceledException) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
_logger.LogInformation("Worker service shutting down"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |