Fix workflow memory issues
This commit is contained in:
parent
71e55ea999
commit
6449969604
2
Elsa.sln
2
Elsa.sln
|
|
@ -115,7 +115,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Testing.Shared", "src\
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Workflows.Sinks", "src\modules\Elsa.Workflows.Sinks\Elsa.Workflows.Sinks.csproj", "{7F1FDA45-C731-4DCC-BFF6-403D4B857A93}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Samples.WorkflowFunctions", "src\samples\console\Elsa.Samples.WorkflowFunctions\Elsa.Samples.WorkflowFunctions.csproj", "{4782CA82-83B0-437E-8C97-636BB8B402EA}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Samples.Console.WorkflowFunctions", "src\samples\console\Elsa.Samples.Console.WorkflowFunctions\Elsa.Samples.Console.WorkflowFunctions.csproj", "{4782CA82-83B0-437E-8C97-636BB8B402EA}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Samples.MyBackendApi", "src\samples\aspnet\Elsa.Samples.MyBackendApi\Elsa.Samples.MyBackendApi.csproj", "{1A37795B-EBAB-4A9F-8CF0-373DA3D4C64A}"
|
||||
EndProject
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ public abstract class WorkflowBase<TResult> : WorkflowBase
|
|||
/// <inheritdoc />
|
||||
protected override ValueTask AfterBuildAsync(IWorkflowBuilder builder, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var variables = builder.Variables ?? new List<Variable>();
|
||||
var variables = builder.Variables;
|
||||
|
||||
if(!variables.Contains(Result))
|
||||
variables.Add(Result);
|
||||
|
|
|
|||
|
|
@ -48,8 +48,9 @@ public abstract class Composite : Activity, IVariableContainer
|
|||
ConfigureActivities(context);
|
||||
|
||||
// Register variables.
|
||||
context.ExpressionExecutionContext.Memory.Declare(Variables);
|
||||
|
||||
foreach (var variable in Variables)
|
||||
variable.Set(context, variable.Value);
|
||||
|
||||
await context.ScheduleActivityAsync(Root, OnRootCompletedAsync);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -293,8 +293,8 @@ public class ActivityExecutionContext : IExecutionContext
|
|||
|
||||
internal void IncrementExecutionCount() => _executionCount++;
|
||||
|
||||
private MemoryBlock? GetMemoryBlock(MemoryBlockReference locationBlockReference) =>
|
||||
ExpressionExecutionContext.Memory.TryGetBlock(locationBlockReference.Id, out var memoryBlock)
|
||||
? memoryBlock
|
||||
: ParentActivityExecutionContext?.GetMemoryBlock(locationBlockReference);
|
||||
private MemoryBlock? GetMemoryBlock(MemoryBlockReference locationBlockReference)
|
||||
{
|
||||
return ExpressionExecutionContext.TryGetBlock(locationBlockReference, out var memoryBlock) ? memoryBlock : default;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
using Elsa.Extensions;
|
||||
using Elsa.Samples.Console.WorkflowFunctions.Workflows;
|
||||
using Elsa.Samples.WorkflowFunctions.Workflows;
|
||||
using Elsa.Workflows.Core.Contracts;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
|
@ -3,7 +3,7 @@ using Elsa.Workflows.Core.Abstractions;
|
|||
using Elsa.Workflows.Core.Activities;
|
||||
using Elsa.Workflows.Core.Contracts;
|
||||
|
||||
namespace Elsa.Samples.WorkflowFunctions.Workflows;
|
||||
namespace Elsa.Samples.Console.WorkflowFunctions.Workflows;
|
||||
|
||||
/// <summary>
|
||||
/// A simple workflow that takes two numbers as runtime workflow input and adds them together and returns the result as the workflow's result.
|
||||
|
|
@ -4,7 +4,7 @@ using Elsa.Workflows.Core.Activities;
|
|||
using Elsa.Workflows.Core.Contracts;
|
||||
using Elsa.Workflows.Core.Models;
|
||||
|
||||
namespace Elsa.Samples.WorkflowFunctions.Workflows;
|
||||
namespace Elsa.Samples.Console.WorkflowFunctions.Workflows;
|
||||
|
||||
/// <summary>
|
||||
/// A workflow that takes a list of numbers as runtime workflow input and returns the sum.
|
||||
|
|
@ -14,15 +14,12 @@ public class SumInputsWorkflow : WorkflowBase<float>
|
|||
protected override void Build(IWorkflowBuilder builder)
|
||||
{
|
||||
// Attach workflow variables.
|
||||
var currentSum = new Variable<float>();
|
||||
var currentValue = new Variable<float>();
|
||||
|
||||
builder.WithVariable(currentSum);
|
||||
var currentSum = builder.WithVariable<float>();
|
||||
var currentValue = builder.WithVariable<float>();
|
||||
|
||||
// Define the sum logic.
|
||||
builder.Root = new Sequence
|
||||
{
|
||||
Variables = { currentValue },
|
||||
Activities =
|
||||
{
|
||||
new ForEach<float>(new Input<ICollection<float>>(context => context.GetInput<float[]>("numbers")!))
|
||||
Loading…
Reference in a new issue