| | | 1 | | using Elsa.Mediator.Contracts; |
| | | 2 | | using Elsa.Workflows.Runtime.Notifications; |
| | | 3 | | using Elsa.Workflows.Runtime.Options; |
| | | 4 | | using Microsoft.Extensions.DependencyInjection; |
| | | 5 | | using Microsoft.Extensions.Logging; |
| | | 6 | | using Microsoft.Extensions.Options; |
| | | 7 | | |
| | | 8 | | namespace Elsa.Workflows.Runtime.Handlers; |
| | | 9 | | |
| | | 10 | | /// <summary> |
| | | 11 | | /// Processes the workflow dispatch outbox after a workflow state commit. |
| | | 12 | | /// </summary> |
| | 645 | 13 | | public class ProcessWorkflowDispatchOutbox(IServiceProvider serviceProvider, IOptions<WorkflowDispatcherOptions> options |
| | | 14 | | { |
| | | 15 | | /// <inheritdoc /> |
| | | 16 | | public async Task HandleAsync(WorkflowStateCommitted notification, CancellationToken cancellationToken) |
| | | 17 | | { |
| | 539 | 18 | | if (!options.Value.UseTransactionalOutbox || !options.Value.ProcessOutboxAfterCommit) |
| | 536 | 19 | | return; |
| | | 20 | | |
| | 3 | 21 | | if (!notification.WorkflowState.HasWorkflowDispatchOutboxItems()) |
| | 1 | 22 | | return; |
| | | 23 | | |
| | | 24 | | try |
| | | 25 | | { |
| | 2 | 26 | | var processor = serviceProvider.GetRequiredService<IWorkflowDispatchOutboxProcessor>(); |
| | 2 | 27 | | await processor.TryProcessAsync(cancellationToken); |
| | 1 | 28 | | } |
| | 0 | 29 | | catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested) |
| | | 30 | | { |
| | 0 | 31 | | throw; |
| | | 32 | | } |
| | 1 | 33 | | catch (Exception e) when (e is not OperationCanceledException) |
| | | 34 | | { |
| | 1 | 35 | | logger.LogError(e, "Failed to process workflow dispatch outbox after workflow state commit; the recurring ou |
| | 1 | 36 | | } |
| | 539 | 37 | | } |
| | | 38 | | } |