| | | 1 | | using Elsa.Workflows.Options; |
| | | 2 | | using Microsoft.Extensions.Logging; |
| | | 3 | | |
| | | 4 | | namespace Elsa.Workflows; |
| | | 5 | | |
| | | 6 | | /// <inheritdoc /> |
| | 421 | 7 | | public class ActivityInvoker( |
| | 421 | 8 | | IActivityExecutionPipeline pipeline, |
| | 421 | 9 | | ILoggerStateGenerator<ActivityExecutionContext> loggerStateGenerator, |
| | 421 | 10 | | ILogger<ActivityInvoker> logger) |
| | | 11 | | : IActivityInvoker |
| | | 12 | | { |
| | | 13 | | |
| | | 14 | | /// <inheritdoc /> |
| | | 15 | | public async Task<ActivityExecutionContext> InvokeAsync(WorkflowExecutionContext workflowExecutionContext, IActivity |
| | | 16 | | { |
| | | 17 | | // Setup an activity execution context, potentially reusing an existing one if requested. |
| | 3019 | 18 | | var existingActivityExecutionContext = options?.ExistingActivityExecutionContext; |
| | | 19 | | |
| | | 20 | | // Perform a lookup to make sure the activity execution context is part of the workflow execution context. |
| | 3019 | 21 | | var activityExecutionContext = existingActivityExecutionContext != null |
| | 42 | 22 | | ? workflowExecutionContext.ActivityExecutionContexts.FirstOrDefault(x => x.Id == existingActivityExecutionCo |
| | 3019 | 23 | | : null; |
| | | 24 | | |
| | 3019 | 25 | | if (activityExecutionContext == null) |
| | | 26 | | { |
| | | 27 | | // Create a new activity execution context. |
| | 2983 | 28 | | activityExecutionContext = await workflowExecutionContext.CreateActivityExecutionContextAsync(activity, opti |
| | 2983 | 29 | | activityExecutionContext.Taint(); |
| | | 30 | | |
| | | 31 | | // Add the activity context to the workflow context. |
| | 2983 | 32 | | workflowExecutionContext.AddActivityExecutionContext(activityExecutionContext); |
| | | 33 | | } |
| | | 34 | | |
| | | 35 | | // Execute the activity execution pipeline. |
| | 3019 | 36 | | await InvokeAsync(activityExecutionContext); |
| | | 37 | | |
| | 3019 | 38 | | return activityExecutionContext; |
| | 3019 | 39 | | } |
| | | 40 | | |
| | | 41 | | /// <inheritdoc /> |
| | | 42 | | public async Task InvokeAsync(ActivityExecutionContext activityExecutionContext) |
| | | 43 | | { |
| | 3019 | 44 | | var loggerState = loggerStateGenerator.GenerateLoggerState(activityExecutionContext); |
| | 3019 | 45 | | using var loggingScope = logger.BeginScope(loggerState); |
| | | 46 | | |
| | | 47 | | // Execute the activity execution pipeline. |
| | 3019 | 48 | | await pipeline.ExecuteAsync(activityExecutionContext); |
| | 3019 | 49 | | } |
| | | 50 | | } |