diff --git a/src/modules/Elsa.Workflows.Core/Contracts/IVariablePersistenceManager.cs b/src/modules/Elsa.Workflows.Core/Contracts/IVariablePersistenceManager.cs
index aa4105e3b..bb61acd67 100644
--- a/src/modules/Elsa.Workflows.Core/Contracts/IVariablePersistenceManager.cs
+++ b/src/modules/Elsa.Workflows.Core/Contracts/IVariablePersistenceManager.cs
@@ -19,7 +19,12 @@ public interface IVariablePersistenceManager
Task SaveVariablesAsync(WorkflowExecutionContext context);
///
- /// Deletes the specified variables from the .
+ /// Deletes the specified variables from the .
///
Task DeleteVariablesAsync(ActivityExecutionContext context);
+
+ ///
+ /// Deletes the specified variables from the .
+ ///
+ Task DeleteVariablesAsync(WorkflowExecutionContext context);
}
\ 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 2ca6dcc86..c486c24e8 100644
--- a/src/modules/Elsa.Workflows.Core/Services/VariablePersistenceManager.cs
+++ b/src/modules/Elsa.Workflows.Core/Services/VariablePersistenceManager.cs
@@ -120,6 +120,33 @@ public class VariablePersistenceManager(IStorageDriverManager storageDriverManag
}
}
+ ///
+ public async Task DeleteVariablesAsync(WorkflowExecutionContext context)
+ {
+ var cancellationToken = context.CancellationTokens.ApplicationCancellationToken;
+ var activityContexts = context.ActivityExecutionContexts.ToList();
+
+ foreach (var activityContext in activityContexts)
+ {
+ var variables = GetLocalVariables(activityContext).ToList();
+
+ foreach (var variable in variables)
+ {
+ var block = variable.GetBlock(activityContext.ExpressionExecutionContext);
+ var metadata = (VariableBlockMetadata)block.Metadata!;
+ var driver = _storageDriverManager.Get(metadata.StorageDriverType!);
+
+ if (driver == null)
+ continue;
+
+ var id = GetStateId(variable);
+ var storageDriverContext = new StorageDriverContext(activityContext, variable, cancellationToken);
+
+ await driver.DeleteAsync(id, storageDriverContext);
+ }
+ }
+ }
+
private IEnumerable GetLocalVariables(IExecutionContext context) => context.Variables;
private MemoryBlock EnsureBlock(MemoryRegister register, Variable variable)