diff --git a/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowInstances/Variables/List/Endpoint.cs b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowInstances/Variables/List/Endpoint.cs index eec16fa80..2ef0efb7e 100644 --- a/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowInstances/Variables/List/Endpoint.cs +++ b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowInstances/Variables/List/Endpoint.cs @@ -27,7 +27,7 @@ internal class List(IWorkflowInstanceVariableManager workflowInstanceVariableMan return; } - var variables = await workflowInstanceVariableManager.GetVariablesAsync(workflowInstanceId, cancellationToken).ToList(); + var variables = await workflowInstanceVariableManager.GetVariablesAsync(workflowInstanceId, true,cancellationToken).ToList(); var variableModels = variables.Select(x => new ResolvedVariableModel(x.Variable.Id, x.Variable.Name, x.Value)).ToList(); var response = new ListResponse(variableModels); await SendOkAsync(response, cancellationToken); diff --git a/src/modules/Elsa.Workflows.Core/Contracts/IStorageDriver.cs b/src/modules/Elsa.Workflows.Core/Contracts/IStorageDriver.cs index 9464b1ef7..1b8fad2cd 100644 --- a/src/modules/Elsa.Workflows.Core/Contracts/IStorageDriver.cs +++ b/src/modules/Elsa.Workflows.Core/Contracts/IStorageDriver.cs @@ -10,6 +10,11 @@ public interface IStorageDriver /// double Priority { get; } + /// + /// A list of tags assigned to the driver used to describe the data contents. + /// + StorageDriverTag[] Tags { get; } + /// /// Writes a value to the storage driver. /// diff --git a/src/modules/Elsa.Workflows.Core/Contracts/IVariablePersistenceManager.cs b/src/modules/Elsa.Workflows.Core/Contracts/IVariablePersistenceManager.cs index 8fa1a1ec5..59cb3f113 100644 --- a/src/modules/Elsa.Workflows.Core/Contracts/IVariablePersistenceManager.cs +++ b/src/modules/Elsa.Workflows.Core/Contracts/IVariablePersistenceManager.cs @@ -6,9 +6,12 @@ namespace Elsa.Workflows; public interface IVariablePersistenceManager { /// - /// Loads the variables into the specified . + /// Loads the variables into the specified . /// - Task LoadVariablesAsync(WorkflowExecutionContext context); + /// + /// + /// + Task LoadVariablesAsync(WorkflowExecutionContext context, bool excludeValueRetrievalForLargeDataDrivers = false); /// /// Persists all persistable variables from the specified . diff --git a/src/modules/Elsa.Workflows.Core/Contracts/IWorkflowInstanceVariableReader.cs b/src/modules/Elsa.Workflows.Core/Contracts/IWorkflowInstanceVariableReader.cs index a311cbabe..d14a5ac62 100644 --- a/src/modules/Elsa.Workflows.Core/Contracts/IWorkflowInstanceVariableReader.cs +++ b/src/modules/Elsa.Workflows.Core/Contracts/IWorkflowInstanceVariableReader.cs @@ -9,7 +9,8 @@ public interface IWorkflowInstanceVariableReader /// Retrieves all variables from the specified . /// /// The context of the workflow execution. + /// /// The cancellation token to cancel the operation. /// A task that represents the asynchronous operation. The task result contains a collection of instances. - Task> GetVariables(WorkflowExecutionContext workflowExecutionContext, CancellationToken cancellationToken = default); + Task> GetVariables(WorkflowExecutionContext workflowExecutionContext, bool excludeValueRetrievalForLargeDataDrivers = false, CancellationToken cancellationToken = default); } \ No newline at end of file diff --git a/src/modules/Elsa.Workflows.Core/Enums/StorageDriverTag.cs b/src/modules/Elsa.Workflows.Core/Enums/StorageDriverTag.cs new file mode 100644 index 000000000..93a099c49 --- /dev/null +++ b/src/modules/Elsa.Workflows.Core/Enums/StorageDriverTag.cs @@ -0,0 +1,6 @@ +namespace Elsa.Workflows; + +public enum StorageDriverTag +{ + LargeData +} \ No newline at end of file diff --git a/src/modules/Elsa.Workflows.Core/Services/DefaultWorkflowInstanceVariableReader.cs b/src/modules/Elsa.Workflows.Core/Services/DefaultWorkflowInstanceVariableReader.cs index 2bae458ae..48aa3e6db 100644 --- a/src/modules/Elsa.Workflows.Core/Services/DefaultWorkflowInstanceVariableReader.cs +++ b/src/modules/Elsa.Workflows.Core/Services/DefaultWorkflowInstanceVariableReader.cs @@ -2,7 +2,7 @@ namespace Elsa.Workflows; public class DefaultWorkflowInstanceVariableReader(IVariablePersistenceManager variablePersistenceManager) : IWorkflowInstanceVariableReader { - public async Task> GetVariables(WorkflowExecutionContext workflowExecutionContext, CancellationToken cancellationToken = default) + public async Task> GetVariables(WorkflowExecutionContext workflowExecutionContext, bool excludeValueRetrievalForLargeDataDrivers = false, CancellationToken cancellationToken = default) { var workflow = workflowExecutionContext.Workflow; var workflowVariables = workflow.Variables; @@ -11,7 +11,7 @@ public class DefaultWorkflowInstanceVariableReader(IVariablePersistenceManager v if (rootWorkflowActivityExecutionContext == null) return []; - await variablePersistenceManager.LoadVariablesAsync(workflowExecutionContext); + await variablePersistenceManager.LoadVariablesAsync(workflowExecutionContext, excludeValueRetrievalForLargeDataDrivers); var resolvedVariables = new List(); foreach (var workflowVariable in workflowVariables) diff --git a/src/modules/Elsa.Workflows.Core/Services/MemoryStorageDriver.cs b/src/modules/Elsa.Workflows.Core/Services/MemoryStorageDriver.cs index a110edcfe..458d6a55d 100644 --- a/src/modules/Elsa.Workflows.Core/Services/MemoryStorageDriver.cs +++ b/src/modules/Elsa.Workflows.Core/Services/MemoryStorageDriver.cs @@ -9,8 +9,10 @@ namespace Elsa.Workflows; public class MemoryStorageDriver : IStorageDriver { private readonly IDictionary _dictionary = new Dictionary(); - + /// public double Priority => 0; + /// + public StorageDriverTag[] Tags => []; /// public ValueTask WriteAsync(string id, object value, StorageDriverContext context) diff --git a/src/modules/Elsa.Workflows.Core/Services/VariablePersistenceManager.cs b/src/modules/Elsa.Workflows.Core/Services/VariablePersistenceManager.cs index ccecb32c9..d0dadf07d 100644 --- a/src/modules/Elsa.Workflows.Core/Services/VariablePersistenceManager.cs +++ b/src/modules/Elsa.Workflows.Core/Services/VariablePersistenceManager.cs @@ -8,7 +8,7 @@ namespace Elsa.Workflows; public class VariablePersistenceManager(IStorageDriverManager storageDriverManager) : IVariablePersistenceManager { /// - public async Task LoadVariablesAsync(WorkflowExecutionContext workflowExecutionContext) + public async Task LoadVariablesAsync(WorkflowExecutionContext workflowExecutionContext, bool excludeValueRetrievalForLargeDataDrivers = false) { var cancellationToken = workflowExecutionContext.CancellationToken; var contexts = workflowExecutionContext.ActivityExecutionContexts.ToList(); @@ -34,6 +34,9 @@ public class VariablePersistenceManager(IStorageDriverManager storageDriverManag if (driver == null) continue; + if (excludeValueRetrievalForLargeDataDrivers && driver.Tags.Contains(StorageDriverTag.LargeData)) + continue; + var id = GetStateId(variable); var value = await driver.ReadAsync(id, storageDriverContext); if (value == null) continue; diff --git a/src/modules/Elsa.Workflows.Core/VariableStorageDrivers/WorkflowInstanceStorageDriver.cs b/src/modules/Elsa.Workflows.Core/VariableStorageDrivers/WorkflowInstanceStorageDriver.cs index a321269aa..182c809c3 100644 --- a/src/modules/Elsa.Workflows.Core/VariableStorageDrivers/WorkflowInstanceStorageDriver.cs +++ b/src/modules/Elsa.Workflows.Core/VariableStorageDrivers/WorkflowInstanceStorageDriver.cs @@ -17,8 +17,11 @@ public class WorkflowInstanceStorageDriver : IStorageDriver /// The key used to store the variables in the workflow state. /// public const string VariablesDictionaryStateKey = "Variables"; - + + /// public double Priority => 5; + /// + public StorageDriverTag[] Tags => []; /// public ValueTask WriteAsync(string id, object value, StorageDriverContext context) diff --git a/src/modules/Elsa.Workflows.Core/VariableStorageDrivers/WorkflowStorageDriver.cs b/src/modules/Elsa.Workflows.Core/VariableStorageDrivers/WorkflowStorageDriver.cs index 96dd585e9..fbbe39ec8 100644 --- a/src/modules/Elsa.Workflows.Core/VariableStorageDrivers/WorkflowStorageDriver.cs +++ b/src/modules/Elsa.Workflows.Core/VariableStorageDrivers/WorkflowStorageDriver.cs @@ -20,6 +20,8 @@ public class WorkflowStorageDriver : IStorageDriver /// public double Priority => -1; + /// + public StorageDriverTag[] Tags => []; /// public ValueTask WriteAsync(string id, object value, StorageDriverContext context) diff --git a/src/modules/Elsa.Workflows.Management/Contracts/IWorkflowInstanceVariableManager.cs b/src/modules/Elsa.Workflows.Management/Contracts/IWorkflowInstanceVariableManager.cs index 965e769fe..0dd3a5b10 100644 --- a/src/modules/Elsa.Workflows.Management/Contracts/IWorkflowInstanceVariableManager.cs +++ b/src/modules/Elsa.Workflows.Management/Contracts/IWorkflowInstanceVariableManager.cs @@ -6,17 +6,19 @@ public interface IWorkflowInstanceVariableManager /// Retrieves all variables for the specified workflow instance. /// /// The ID of the workflow instance. + /// /// The cancellation token to cancel the operation. /// A task that represents the asynchronous operation. The task result contains a collection of instances. - Task> GetVariablesAsync(string workflowInstanceId, CancellationToken cancellationToken = default); + Task> GetVariablesAsync(string workflowInstanceId, bool excludeValueRetrievalForLargeDataDrivers = false, CancellationToken cancellationToken = default); /// /// Retrieves all variables from the specified . /// /// The context of the workflow execution. + /// /// The cancellation token to cancel the operation. /// A task that represents the asynchronous operation. The task result contains a collection of instances. - Task> GetVariablesAsync(WorkflowExecutionContext workflowExecutionContext, CancellationToken cancellationToken = default); + Task> GetVariablesAsync(WorkflowExecutionContext workflowExecutionContext, bool excludeValueRetrievalForLargeDataDrivers = false, CancellationToken cancellationToken = default); /// /// Sets the specified variables in the specified workflow instance. diff --git a/src/modules/Elsa.Workflows.Management/Services/WorkflowInstanceVariableManager.cs b/src/modules/Elsa.Workflows.Management/Services/WorkflowInstanceVariableManager.cs index 9fae974f4..1dcfeedd7 100644 --- a/src/modules/Elsa.Workflows.Management/Services/WorkflowInstanceVariableManager.cs +++ b/src/modules/Elsa.Workflows.Management/Services/WorkflowInstanceVariableManager.cs @@ -7,16 +7,16 @@ public class WorkflowInstanceVariableManager( IWorkflowInstanceVariableReader variableReader, IWorkflowInstanceVariableWriter variableWriter) : IWorkflowInstanceVariableManager { - public async Task> GetVariablesAsync(string workflowInstanceId, CancellationToken cancellationToken = default) + public async Task> GetVariablesAsync(string workflowInstanceId, bool excludeValueRetrievalForLargeDataDrivers = false, CancellationToken cancellationToken = default) { var workflowExecutionContext = await GetWorkflowExecutionContextAsync(workflowInstanceId, cancellationToken); if (workflowExecutionContext == null) return []; - return await variableReader.GetVariables(workflowExecutionContext, cancellationToken); + return await variableReader.GetVariables(workflowExecutionContext, excludeValueRetrievalForLargeDataDrivers, cancellationToken); } - public Task> GetVariablesAsync(WorkflowExecutionContext workflowExecutionContext, CancellationToken cancellationToken = default) + public Task> GetVariablesAsync(WorkflowExecutionContext workflowExecutionContext, bool excludeValueRetrievalForLargeDataDrivers = false, CancellationToken cancellationToken = default) { - return variableReader.GetVariables(workflowExecutionContext, cancellationToken); + return variableReader.GetVariables(workflowExecutionContext, excludeValueRetrievalForLargeDataDrivers, cancellationToken); } public async Task> SetVariablesAsync(string workflowInstanceId, IEnumerable variables, CancellationToken cancellationToken = default)