| | | 1 | | using Elsa.Mediator.Contracts; |
| | | 2 | | using Elsa.Workflows.Helpers; |
| | | 3 | | using Elsa.Workflows.Notifications; |
| | | 4 | | using Elsa.Workflows.Runtime.Activities; |
| | | 5 | | using Elsa.Workflows.Runtime.Stimuli; |
| | | 6 | | using JetBrains.Annotations; |
| | | 7 | | |
| | | 8 | | namespace Elsa.Workflows.Runtime.Handlers; |
| | | 9 | | |
| | | 10 | | /// <summary> |
| | | 11 | | /// Resumes any blocking <see cref="DispatchWorkflow"/> activities when its child workflow completes. |
| | | 12 | | /// </summary> |
| | | 13 | | [PublicAPI] |
| | 467 | 14 | | internal class ResumeDispatchWorkflowActivity(IBookmarkQueue bookmarkQueue, IStimulusHasher stimulusHasher) : INotificat |
| | | 15 | | { |
| | 2 | 16 | | private static readonly string ActivityTypeName = ActivityTypeNameHelper.GenerateTypeName<DispatchWorkflow>(); |
| | | 17 | | |
| | | 18 | | public async Task HandleAsync(WorkflowExecuted notification, CancellationToken cancellationToken) |
| | | 19 | | { |
| | 465 | 20 | | var workflowState = notification.WorkflowState; |
| | | 21 | | |
| | 465 | 22 | | if (workflowState.Status != WorkflowStatus.Finished) |
| | 64 | 23 | | return; |
| | | 24 | | |
| | 401 | 25 | | var props = workflowState.Properties; |
| | 401 | 26 | | var waitForCompletion = props.TryGetValue("WaitForCompletion", out var waitForCompletionValue) && (bool)waitForC |
| | | 27 | | |
| | 401 | 28 | | if (!waitForCompletion) |
| | 382 | 29 | | return; |
| | | 30 | | |
| | 19 | 31 | | var parentInstanceId = (string)props["ParentInstanceId"]; |
| | 19 | 32 | | var stimulus = new DispatchWorkflowStimulus(notification.WorkflowState.Id); |
| | 19 | 33 | | var input = workflowState.Output; |
| | | 34 | | |
| | 19 | 35 | | var bookmarkQueueItem = new NewBookmarkQueueItem |
| | 19 | 36 | | { |
| | 19 | 37 | | WorkflowInstanceId = parentInstanceId, |
| | 19 | 38 | | ActivityTypeName = ActivityTypeName, |
| | 19 | 39 | | StimulusHash = stimulusHasher.Hash(ActivityTypeName, stimulus), |
| | 19 | 40 | | Options = new() |
| | 19 | 41 | | { |
| | 19 | 42 | | Input = input |
| | 19 | 43 | | } |
| | 19 | 44 | | }; |
| | | 45 | | |
| | 19 | 46 | | await bookmarkQueue.EnqueueAsync(bookmarkQueueItem, cancellationToken); |
| | 465 | 47 | | } |
| | | 48 | | } |