| | | 1 | | using Elsa.Common.Multitenancy; |
| | | 2 | | using Elsa.Mediator; |
| | | 3 | | using Elsa.Mediator.Contracts; |
| | | 4 | | using Elsa.Tenants.Mediator; |
| | | 5 | | using Elsa.Workflows.Runtime.Commands; |
| | | 6 | | using Elsa.Workflows.Runtime.Requests; |
| | | 7 | | using Elsa.Workflows.Runtime.Responses; |
| | | 8 | | |
| | | 9 | | namespace Elsa.Workflows.Runtime; |
| | | 10 | | |
| | | 11 | | /// <summary> |
| | | 12 | | /// A simple implementation that queues the specified request for workflow execution on a non-durable background worker. |
| | | 13 | | /// </summary> |
| | 329 | 14 | | public class BackgroundWorkflowDispatcher(ICommandSender commandSender, ITenantAccessor tenantAccessor) : IWorkflowDispa |
| | | 15 | | { |
| | | 16 | | /// <inheritdoc /> |
| | | 17 | | public async Task<DispatchWorkflowResponse> DispatchAsync(DispatchWorkflowDefinitionRequest request, DispatchWorkflo |
| | | 18 | | { |
| | 23 | 19 | | var command = new DispatchWorkflowDefinitionCommand(request.DefinitionVersionId) |
| | 23 | 20 | | { |
| | 23 | 21 | | Input = request.Input, |
| | 23 | 22 | | Properties = request.Properties, |
| | 23 | 23 | | CorrelationId = request.CorrelationId, |
| | 23 | 24 | | InstanceId = request.InstanceId, |
| | 23 | 25 | | TriggerActivityId = request.TriggerActivityId, |
| | 23 | 26 | | ParentWorkflowInstanceId = request.ParentWorkflowInstanceId, |
| | 23 | 27 | | }; |
| | | 28 | | |
| | 23 | 29 | | await commandSender.SendAsync(command, CommandStrategy.Background, CreateHeaders(), cancellationToken); |
| | 23 | 30 | | return DispatchWorkflowResponse.Success(); |
| | 23 | 31 | | } |
| | | 32 | | |
| | | 33 | | /// <inheritdoc /> |
| | | 34 | | public async Task<DispatchWorkflowResponse> DispatchAsync(DispatchWorkflowInstanceRequest request, DispatchWorkflowO |
| | | 35 | | { |
| | 0 | 36 | | var command = new DispatchWorkflowInstanceCommand(request.InstanceId){ |
| | 0 | 37 | | BookmarkId = request.BookmarkId, |
| | 0 | 38 | | ActivityHandle = request.ActivityHandle, |
| | 0 | 39 | | Input = request.Input, |
| | 0 | 40 | | Properties = request.Properties, |
| | 0 | 41 | | CorrelationId = request.CorrelationId}; |
| | | 42 | | |
| | 0 | 43 | | await commandSender.SendAsync(command, CommandStrategy.Background, CreateHeaders(), cancellationToken); |
| | 0 | 44 | | return DispatchWorkflowResponse.Success(); |
| | 0 | 45 | | } |
| | | 46 | | |
| | | 47 | | /// <inheritdoc /> |
| | | 48 | | public async Task<DispatchWorkflowResponse> DispatchAsync(DispatchTriggerWorkflowsRequest request, DispatchWorkflowO |
| | | 49 | | { |
| | 0 | 50 | | var command = new DispatchTriggerWorkflowsCommand(request.ActivityTypeName, request.BookmarkPayload) |
| | 0 | 51 | | { |
| | 0 | 52 | | CorrelationId = request.CorrelationId, |
| | 0 | 53 | | WorkflowInstanceId = request.WorkflowInstanceId, |
| | 0 | 54 | | ActivityInstanceId = request.ActivityInstanceId, |
| | 0 | 55 | | Input = request.Input, |
| | 0 | 56 | | Properties = request.Properties |
| | 0 | 57 | | }; |
| | 0 | 58 | | await commandSender.SendAsync(command, CommandStrategy.Background, CreateHeaders(), cancellationToken); |
| | 0 | 59 | | return DispatchWorkflowResponse.Success(); |
| | 0 | 60 | | } |
| | | 61 | | |
| | | 62 | | /// <inheritdoc /> |
| | | 63 | | public async Task<DispatchWorkflowResponse> DispatchAsync(DispatchResumeWorkflowsRequest request, DispatchWorkflowOp |
| | | 64 | | { |
| | 0 | 65 | | var command = new DispatchResumeWorkflowsCommand(request.ActivityTypeName, request.BookmarkPayload) |
| | 0 | 66 | | { |
| | 0 | 67 | | CorrelationId = request.CorrelationId, |
| | 0 | 68 | | WorkflowInstanceId = request.WorkflowInstanceId, |
| | 0 | 69 | | ActivityInstanceId = request.ActivityInstanceId, |
| | 0 | 70 | | Input = request.Input |
| | 0 | 71 | | }; |
| | 0 | 72 | | await commandSender.SendAsync(command, CommandStrategy.Background, CreateHeaders(), cancellationToken); |
| | 0 | 73 | | return DispatchWorkflowResponse.Success(); |
| | 0 | 74 | | } |
| | | 75 | | |
| | | 76 | | private IDictionary<object, object> CreateHeaders() |
| | | 77 | | { |
| | 23 | 78 | | return TenantHeaders.CreateHeaders(tenantAccessor.Tenant?.Id); |
| | | 79 | | } |
| | | 80 | | } |