diff --git a/src/modules/Elsa.Workflows.Core/Contracts/IVariablePersistenceManager.cs b/src/modules/Elsa.Workflows.Core/Contracts/IVariablePersistenceManager.cs index bb61acd67..a08b54a85 100644 --- a/src/modules/Elsa.Workflows.Core/Contracts/IVariablePersistenceManager.cs +++ b/src/modules/Elsa.Workflows.Core/Contracts/IVariablePersistenceManager.cs @@ -21,10 +21,16 @@ public interface IVariablePersistenceManager /// /// Deletes the specified variables from the . /// - Task DeleteVariablesAsync(ActivityExecutionContext context); + /// + /// + /// + Task DeleteVariablesAsync(ActivityExecutionContext context, IEnumerable? includeTags = default); /// /// Deletes the specified variables from the . /// - Task DeleteVariablesAsync(WorkflowExecutionContext context); + /// + /// + /// + Task DeleteVariablesAsync(WorkflowExecutionContext context, IEnumerable? includeTags = default); } \ No newline at end of file diff --git a/src/modules/Elsa.Workflows.Core/Services/VariablePersistenceManager.cs b/src/modules/Elsa.Workflows.Core/Services/VariablePersistenceManager.cs index a383253e2..9943b2462 100644 --- a/src/modules/Elsa.Workflows.Core/Services/VariablePersistenceManager.cs +++ b/src/modules/Elsa.Workflows.Core/Services/VariablePersistenceManager.cs @@ -100,11 +100,12 @@ public class VariablePersistenceManager(IStorageDriverManager storageDriverManag } /// - public async Task DeleteVariablesAsync(ActivityExecutionContext context) + public async Task DeleteVariablesAsync(ActivityExecutionContext context, IEnumerable? includeTags = default) { var register = context.ExpressionExecutionContext.Memory; var variableList = GetLocalVariables(context).ToList(); var cancellationToken = context.CancellationToken; + var includeTagsList = includeTags?.ToList(); foreach (var variable in variableList) { @@ -116,6 +117,9 @@ public class VariablePersistenceManager(IStorageDriverManager storageDriverManag if (driver == null) continue; + + if (includeTagsList != null && !driver.Tags.Any(includeTagsList.Contains)) + continue; var id = GetStateId(variable); var storageDriverContext = new StorageDriverContext(context, variable, cancellationToken); @@ -125,13 +129,14 @@ public class VariablePersistenceManager(IStorageDriverManager storageDriverManag } /// - public async Task DeleteVariablesAsync(WorkflowExecutionContext context) + public async Task DeleteVariablesAsync(WorkflowExecutionContext context, IEnumerable? includeTags = default) { var activityContexts = context.ActivityExecutionContexts.ToList(); - + var includeTagsList = includeTags?.ToList(); + foreach (var activityContext in activityContexts) { - await DeleteVariablesAsync(activityContext); + await DeleteVariablesAsync(activityContext, includeTagsList); } }