| | | 1 | | using Elsa.Extensions; |
| | | 2 | | using Elsa.Mediator.Contracts; |
| | | 3 | | using Elsa.Workflows.Runtime.Entities; |
| | | 4 | | using Elsa.Workflows.Runtime.Notifications; |
| | | 5 | | |
| | | 6 | | namespace Elsa.Workflows.Runtime; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// This implementation saves <see cref="ActivityExecutionRecord"/> directly through the store. |
| | | 10 | | /// </summary> |
| | 437 | 11 | | public class StoreActivityExecutionLogSink( |
| | 437 | 12 | | IActivityExecutionStore activityExecutionStore, |
| | 437 | 13 | | INotificationSender notificationSender) |
| | | 14 | | : ILogRecordSink<ActivityExecutionRecord> |
| | | 15 | | { |
| | | 16 | | /// <inheritdoc /> |
| | | 17 | | public async Task PersistExecutionLogsAsync(WorkflowExecutionContext context, CancellationToken cancellationToken = |
| | | 18 | | { |
| | | 19 | | // Select tainted activity execution contexts to avoid saving untainted ones multiple times. |
| | 4257 | 20 | | var activityExecutionContexts = context.ActivityExecutionContexts.Where(x => x.IsDirty).ToList(); |
| | | 21 | | |
| | 466 | 22 | | if (activityExecutionContexts.Count == 0) |
| | 0 | 23 | | return; |
| | | 24 | | |
| | 4257 | 25 | | var records = await Task.WhenAll(activityExecutionContexts.Select(x => x.GetOrMapCapturedActivityExecutionRecord |
| | 466 | 26 | | await activityExecutionStore.SaveManyAsync(records, cancellationToken); |
| | | 27 | | |
| | | 28 | | // Untaint activity execution contexts. |
| | 8514 | 29 | | foreach (var activityExecutionContext in activityExecutionContexts) |
| | 3791 | 30 | | activityExecutionContext.ClearTaint(); |
| | | 31 | | |
| | 466 | 32 | | await notificationSender.SendAsync(new ActivityExecutionLogUpdated(context, records), cancellationToken); |
| | 466 | 33 | | } |
| | | 34 | | } |