| | | 1 | | using Elsa.Workflows.Runtime; |
| | | 2 | | using Elsa.Workflows.Runtime.Exceptions; |
| | | 3 | | using Elsa.Workflows.Runtime.Messages; |
| | | 4 | | using Microsoft.Extensions.DependencyInjection; |
| | | 5 | | using Microsoft.Extensions.Logging; |
| | | 6 | | |
| | | 7 | | namespace Elsa.Scheduling.Tasks; |
| | | 8 | | |
| | | 9 | | /// <summary> |
| | | 10 | | /// A task that resumes a workflow. |
| | | 11 | | /// </summary> |
| | 18 | 12 | | public class ResumeWorkflowTask(ScheduleExistingWorkflowInstanceRequest request) : ITask |
| | | 13 | | { |
| | | 14 | | /// <inheritdoc /> |
| | | 15 | | public async ValueTask ExecuteAsync(TaskExecutionContext context) |
| | | 16 | | { |
| | 11 | 17 | | var cancellationToken = context.CancellationToken; |
| | 11 | 18 | | var workflowRuntime = context.ServiceProvider.GetRequiredService<IWorkflowRuntime>(); |
| | 11 | 19 | | var logger = context.ServiceProvider.GetRequiredService<ILogger<ResumeWorkflowTask>>(); |
| | | 20 | | |
| | | 21 | | try |
| | | 22 | | { |
| | 11 | 23 | | var workflowClient = await workflowRuntime.CreateClientAsync(request.WorkflowInstanceId, cancellationToken); |
| | 11 | 24 | | var runWorkflowInstanceRequest = new RunWorkflowInstanceRequest |
| | 11 | 25 | | { |
| | 11 | 26 | | Input = request.Input, |
| | 11 | 27 | | Properties = request.Properties, |
| | 11 | 28 | | ActivityHandle = request.ActivityHandle, |
| | 11 | 29 | | BookmarkId = request.BookmarkId |
| | 11 | 30 | | }; |
| | 11 | 31 | | await workflowClient.RunInstanceAsync(runWorkflowInstanceRequest, cancellationToken); |
| | 11 | 32 | | } |
| | 0 | 33 | | catch (WorkflowInstanceNotFoundException ex) |
| | | 34 | | { |
| | 0 | 35 | | logger.LogWarning( |
| | 0 | 36 | | "Scheduled workflow instance {WorkflowInstanceId} no longer exists and was likely deleted. Skipping exec |
| | 0 | 37 | | ex.InstanceId); |
| | 0 | 38 | | } |
| | 11 | 39 | | } |
| | | 40 | | } |