Add Variable parameter to StorageDriverContext

Updated `StorageDriverContext` to include a `Variable` parameter, ensuring more precise context handling for variable-related operations. Adjusted relevant method calls to pass the required `Variable` argument where necessary.
This commit is contained in:
Sipke Schoorstra 2024-12-18 15:37:38 +01:00
parent 8f8f8579a4
commit fb70022e87
2 changed files with 5 additions and 4 deletions

View file

@ -1,8 +1,9 @@
using Elsa.Workflows.Contracts;
using Elsa.Workflows.Memory;
namespace Elsa.Workflows;
/// <summary>
/// Provides context for storage drivers.
/// </summary>
public record StorageDriverContext(IExecutionContext ExecutionContext, CancellationToken CancellationToken);
public record StorageDriverContext(IExecutionContext ExecutionContext, Variable Variable, CancellationToken CancellationToken);

View file

@ -31,7 +31,7 @@ public class VariablePersistenceManager : IVariablePersistenceManager
foreach (var variable in variables)
{
context.ExpressionExecutionContext.Memory.Declare(variable);
var storageDriverContext = new StorageDriverContext(context, cancellationToken);
var storageDriverContext = new StorageDriverContext(context, variable, cancellationToken);
var register = context.ExpressionExecutionContext.Memory;
var block = EnsureBlock(register, variable);
var metadata = (VariableBlockMetadata)block.Metadata!;
@ -62,7 +62,6 @@ public class VariablePersistenceManager : IVariablePersistenceManager
foreach (var context in contexts)
{
var variables = GetLocalVariables(context).ToList();
var storageDriverContext = new StorageDriverContext(context, cancellationToken);
foreach (var variable in variables)
{
@ -75,6 +74,7 @@ public class VariablePersistenceManager : IVariablePersistenceManager
var id = GetStateId(variable);
var value = block.Value;
var storageDriverContext = new StorageDriverContext(context, variable, cancellationToken);
if (value == null)
await driver.DeleteAsync(id, storageDriverContext);
@ -91,7 +91,6 @@ public class VariablePersistenceManager : IVariablePersistenceManager
var register = context.ExpressionExecutionContext.Memory;
var variableList = GetLocalVariables(context).ToList();
var cancellationToken = context.CancellationToken;
var storageDriverContext = new StorageDriverContext(context, cancellationToken);
foreach (var variable in variableList)
{
@ -105,6 +104,7 @@ public class VariablePersistenceManager : IVariablePersistenceManager
continue;
var id = GetStateId(variable);
var storageDriverContext = new StorageDriverContext(context, variable, cancellationToken);
await driver.DeleteAsync(id, storageDriverContext);
register.Blocks.Remove(variable.Id);
}