| | | 1 | | using Elsa.Alterations.Core.Enums; |
| | | 2 | | using Elsa.Alterations.Core.Notifications; |
| | | 3 | | using Elsa.Mediator.Contracts; |
| | | 4 | | using Elsa.Workflows.Runtime; |
| | | 5 | | using Elsa.Workflows.Runtime.Contracts; |
| | | 6 | | using Elsa.Workflows.Runtime.Requests; |
| | | 7 | | using JetBrains.Annotations; |
| | | 8 | | |
| | | 9 | | namespace Elsa.Alterations.Handlers; |
| | | 10 | | |
| | | 11 | | /// <summary> |
| | | 12 | | /// Resumes a workflow instance when an alteration job has been completed and the workflow contains scheduled work. |
| | | 13 | | /// </summary> |
| | | 14 | | [UsedImplicitly] |
| | | 15 | | public class ResumeWorkflowInstance : INotificationHandler<AlterationJobCompleted> |
| | | 16 | | { |
| | | 17 | | private readonly IWorkflowDispatcher _workflowDispatcher; |
| | | 18 | | |
| | | 19 | | /// <summary> |
| | | 20 | | /// Initializes a new instance of the <see cref="ResumeWorkflowInstance"/> class. |
| | | 21 | | /// </summary> |
| | 320 | 22 | | public ResumeWorkflowInstance(IWorkflowDispatcher workflowDispatcher) |
| | | 23 | | { |
| | 320 | 24 | | _workflowDispatcher = workflowDispatcher; |
| | 320 | 25 | | } |
| | | 26 | | |
| | | 27 | | /// <inheritdoc /> |
| | | 28 | | public async Task HandleAsync(AlterationJobCompleted notification, CancellationToken cancellationToken) |
| | | 29 | | { |
| | 0 | 30 | | var job = notification.Job; |
| | | 31 | | |
| | | 32 | | // Check if job is completed. |
| | 0 | 33 | | if(job.Status != AlterationJobStatus.Completed) |
| | 0 | 34 | | return; |
| | | 35 | | |
| | | 36 | | // Check if the workflow contains scheduled work. |
| | 0 | 37 | | if(!notification.WorkflowContainsScheduledWork) |
| | 0 | 38 | | return; |
| | | 39 | | |
| | | 40 | | // Resume workflow instance. |
| | 0 | 41 | | await _workflowDispatcher.DispatchAsync(new DispatchWorkflowInstanceRequest(job.WorkflowInstanceId), cancellatio |
| | 0 | 42 | | } |
| | | 43 | | } |