Added DeleteVariablesAsync method for the workflow context
This commit is contained in:
parent
b2331f73db
commit
e365d44637
|
|
@ -19,7 +19,12 @@ public interface IVariablePersistenceManager
|
|||
Task SaveVariablesAsync(WorkflowExecutionContext context);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the specified variables from the <see cref="WorkflowExecutionContext"/>.
|
||||
/// Deletes the specified variables from the <see cref="ActivityExecutionContext"/>.
|
||||
/// </summary>
|
||||
Task DeleteVariablesAsync(ActivityExecutionContext context);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the specified variables from the <see cref="WorkflowExecutionContext"/>.
|
||||
/// </summary>
|
||||
Task DeleteVariablesAsync(WorkflowExecutionContext context);
|
||||
}
|
||||
|
|
@ -120,6 +120,33 @@ public class VariablePersistenceManager(IStorageDriverManager storageDriverManag
|
|||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
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<Variable> GetLocalVariables(IExecutionContext context) => context.Variables;
|
||||
|
||||
private MemoryBlock EnsureBlock(MemoryRegister register, Variable variable)
|
||||
|
|
|
|||
Loading…
Reference in a new issue