| | | 1 | | using Elsa.Common.Helpers; |
| | | 2 | | using Microsoft.Extensions.Logging; |
| | | 3 | | |
| | | 4 | | namespace Elsa.Common.Multitenancy; |
| | | 5 | | |
| | 13 | 6 | | public class TenantBackgroundWorkQueueWorker( |
| | 13 | 7 | | ITenantBackgroundWorkQueue workQueue, |
| | 13 | 8 | | IServiceProvider serviceProvider, |
| | 13 | 9 | | ILogger<TenantBackgroundWorkQueueWorker> logger) : BackgroundTask |
| | | 10 | | { |
| | | 11 | | public override async Task ExecuteAsync(CancellationToken cancellationToken) |
| | | 12 | | { |
| | | 13 | | try |
| | | 14 | | { |
| | 13 | 15 | | await using var enumerator = workQueue.DequeueAllAsync(cancellationToken).GetAsyncEnumerator(cancellationTok |
| | 26 | 16 | | while (await enumerator.MoveNextAsync()) |
| | | 17 | | { |
| | | 18 | | try |
| | | 19 | | { |
| | 13 | 20 | | await enumerator.Current(serviceProvider, cancellationToken); |
| | 13 | 21 | | } |
| | 0 | 22 | | catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested) |
| | | 23 | | { |
| | 0 | 24 | | return; |
| | | 25 | | } |
| | 0 | 26 | | catch (Exception e) when (!e.IsFatal()) |
| | | 27 | | { |
| | 0 | 28 | | logger.LogError(e, "A tenant background work item failed."); |
| | 0 | 29 | | } |
| | | 30 | | } |
| | 0 | 31 | | } |
| | 12 | 32 | | catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested) |
| | | 33 | | { |
| | 12 | 34 | | logger.LogDebug("Tenant background work queue worker stopped because cancellation was requested."); |
| | 12 | 35 | | } |
| | 12 | 36 | | } |
| | | 37 | | } |