| | | 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.Options; |
| | | 6 | | using Elsa.Workflows.Runtime.Stimuli; |
| | | 7 | | using JetBrains.Annotations; |
| | | 8 | | |
| | | 9 | | namespace Elsa.Workflows.Runtime.Handlers; |
| | | 10 | | |
| | | 11 | | /// <summary> |
| | | 12 | | /// Resumes any blocking <see cref="BulkDispatchWorkflows"/> activities when its child workflows complete. |
| | | 13 | | /// </summary> |
| | | 14 | | [PublicAPI] |
| | 467 | 15 | | internal class ResumeBulkDispatchWorkflowActivity(IBookmarkQueue bookmarkQueue, IStimulusHasher stimulusHasher) : INotif |
| | | 16 | | { |
| | | 17 | | public async Task HandleAsync(WorkflowExecuted notification, CancellationToken cancellationToken) |
| | | 18 | | { |
| | 465 | 19 | | var workflowState = notification.WorkflowState; |
| | | 20 | | |
| | 465 | 21 | | if (workflowState.Status != WorkflowStatus.Finished) |
| | 64 | 22 | | return; |
| | | 23 | | |
| | 401 | 24 | | var waitForCompletion = workflowState.Properties.TryGetValue("WaitForCompletion", out var waitForCompletionValue |
| | | 25 | | |
| | 401 | 26 | | if (!waitForCompletion) |
| | 382 | 27 | | return; |
| | | 28 | | |
| | 19 | 29 | | var parentInstanceId = (string)workflowState.Properties["ParentInstanceId"]; |
| | 19 | 30 | | var activityTypeName = ActivityTypeNameHelper.GenerateTypeName<BulkDispatchWorkflows>(); |
| | 19 | 31 | | var stimulus = new BulkDispatchWorkflowsStimulus(parentInstanceId); |
| | 19 | 32 | | var stimulusHash = stimulusHasher.Hash(activityTypeName, stimulus); |
| | 19 | 33 | | var workflowInstanceId = workflowState.Id; |
| | 19 | 34 | | var input = new Dictionary<string, object> |
| | 19 | 35 | | { |
| | 19 | 36 | | ["WorkflowOutput"] = workflowState.Output, |
| | 19 | 37 | | ["WorkflowInstanceId"] = workflowInstanceId, |
| | 19 | 38 | | ["WorkflowStatus"] = workflowState.Status, |
| | 19 | 39 | | ["WorkflowSubStatus"] = workflowState.SubStatus, |
| | 19 | 40 | | }; |
| | | 41 | | |
| | 19 | 42 | | var resumeBookmarkOptions = new ResumeBookmarkOptions |
| | 19 | 43 | | { |
| | 19 | 44 | | Input = input |
| | 19 | 45 | | }; |
| | 19 | 46 | | var bookmarkQueueItem = new NewBookmarkQueueItem |
| | 19 | 47 | | { |
| | 19 | 48 | | WorkflowInstanceId = parentInstanceId, |
| | 19 | 49 | | ActivityTypeName = activityTypeName, |
| | 19 | 50 | | StimulusHash = stimulusHash, |
| | 19 | 51 | | Options = resumeBookmarkOptions |
| | 19 | 52 | | }; |
| | 19 | 53 | | await bookmarkQueue.EnqueueAsync(bookmarkQueueItem, cancellationToken); |
| | 465 | 54 | | } |
| | | 55 | | } |