diff --git a/src/modules/Elsa.Workflows.Runtime/Contracts/IWorkflowExecutionLogRecordExtractor.cs b/src/modules/Elsa.Workflows.Runtime/Contracts/IWorkflowExecutionLogRecordExtractor.cs new file mode 100644 index 000000000..0e704bd55 --- /dev/null +++ b/src/modules/Elsa.Workflows.Runtime/Contracts/IWorkflowExecutionLogRecordExtractor.cs @@ -0,0 +1,10 @@ +using Elsa.Workflows.Runtime.Entities; + +namespace Elsa.Workflows.Runtime; + +/// Extracts workflow execution log records. +public interface IWorkflowExecutionLogRecordExtractor +{ + /// Extracts workflow execution logs from a workflow execution context. + IEnumerable ExtractWorkflowExecutionLogs(WorkflowExecutionContext context); +} \ No newline at end of file diff --git a/src/modules/Elsa.Workflows.Runtime/Services/StoreWorkflowExecutionLogSink.cs b/src/modules/Elsa.Workflows.Runtime/Services/StoreWorkflowExecutionLogSink.cs index ecff347d0..d32bb89db 100644 --- a/src/modules/Elsa.Workflows.Runtime/Services/StoreWorkflowExecutionLogSink.cs +++ b/src/modules/Elsa.Workflows.Runtime/Services/StoreWorkflowExecutionLogSink.cs @@ -1,5 +1,4 @@ using Elsa.Mediator.Contracts; -using Elsa.Workflows.Contracts; using Elsa.Workflows.Runtime.Contracts; using Elsa.Workflows.Runtime.Entities; using Elsa.Workflows.Runtime.Notifications; @@ -9,34 +8,12 @@ namespace Elsa.Workflows.Runtime.Services; /// /// This implementation saves directly through the store. /// -public class StoreWorkflowExecutionLogSink(IWorkflowExecutionLogStore store, IIdentityGenerator identityGenerator, INotificationSender notificationSender) : IWorkflowExecutionLogSink +public class StoreWorkflowExecutionLogSink(IWorkflowExecutionLogStore store, IWorkflowExecutionLogRecordExtractor extractor, INotificationSender notificationSender) : IWorkflowExecutionLogSink { /// public async Task PersistExecutionLogsAsync(WorkflowExecutionContext context, CancellationToken cancellationToken) { - var records = context.ExecutionLog.Select(x => new WorkflowExecutionLogRecord - { - Id = identityGenerator.GenerateId(), - ActivityInstanceId = x.ActivityInstanceId, - ParentActivityInstanceId = x.ParentActivityInstanceId, - ActivityNodeId = x.NodeId, - ActivityId = x.ActivityId, - ActivityType = x.ActivityType, - ActivityTypeVersion = x.ActivityTypeVersion, - ActivityName = x.ActivityName, - Message = x.Message, - EventName = x.EventName, - WorkflowDefinitionId = context.Workflow.Identity.DefinitionId, - WorkflowDefinitionVersionId = context.Workflow.Identity.Id, - WorkflowInstanceId = context.Id, - WorkflowVersion = context.Workflow.Version, - Source = x.Source, - ActivityState = x.ActivityState, - Payload = x.Payload, - Timestamp = x.Timestamp, - Sequence = x.Sequence - }).ToList(); - + var records = extractor.ExtractWorkflowExecutionLogs(context).ToList(); await store.AddManyAsync(records, context.CancellationTokens.SystemCancellationToken); await notificationSender.SendAsync(new WorkflowExecutionLogUpdated(context), context.CancellationTokens.SystemCancellationToken); } diff --git a/src/modules/Elsa.Workflows.Runtime/Services/WorkflowExecutionContext.cs b/src/modules/Elsa.Workflows.Runtime/Services/WorkflowExecutionContext.cs new file mode 100644 index 000000000..7badfd3ae --- /dev/null +++ b/src/modules/Elsa.Workflows.Runtime/Services/WorkflowExecutionContext.cs @@ -0,0 +1,35 @@ +using Elsa.Workflows.Contracts; +using Elsa.Workflows.Runtime.Entities; + +namespace Elsa.Workflows.Runtime.Mappers; + +/// +public class WorkflowExecutionLogRecordExtractor(IIdentityGenerator identityGenerator) : IWorkflowExecutionLogRecordExtractor +{ + /// + public IEnumerable ExtractWorkflowExecutionLogs(WorkflowExecutionContext context) + { + return context.ExecutionLog.Select(x => new WorkflowExecutionLogRecord + { + Id = identityGenerator.GenerateId(), + ActivityInstanceId = x.ActivityInstanceId, + ParentActivityInstanceId = x.ParentActivityInstanceId, + ActivityNodeId = x.NodeId, + ActivityId = x.ActivityId, + ActivityType = x.ActivityType, + ActivityTypeVersion = x.ActivityTypeVersion, + ActivityName = x.ActivityName, + Message = x.Message, + EventName = x.EventName, + WorkflowDefinitionId = context.Workflow.Identity.DefinitionId, + WorkflowDefinitionVersionId = context.Workflow.Identity.Id, + WorkflowInstanceId = context.Id, + WorkflowVersion = context.Workflow.Version, + Source = x.Source, + ActivityState = x.ActivityState, + Payload = x.Payload, + Timestamp = x.Timestamp, + Sequence = x.Sequence + }); + } +} \ No newline at end of file