Skip to content

Commit

Permalink
Fix workflow memory issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sfmskywalker committed May 30, 2023
1 parent 71e55ea commit 6449969
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Elsa.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected override ValueTask BeforeBuildAsync(IWorkflowBuilder builder, Cancella
/// <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);
Expand Down
5 changes: 3 additions & 2 deletions src/modules/Elsa.Workflows.Core/Activities/Composite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ protected override async ValueTask ExecuteAsync(ActivityExecutionContext context
ConfigureActivities(context);

// Register variables.
context.ExpressionExecutionContext.Memory.Declare(Variables);

foreach (var variable in Variables)
variable.Set(context, variable.Value);

await context.ScheduleActivityAsync(Root, OnRootCompletedAsync);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ public void ClearCompletionCallbacks()

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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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.
Expand All @@ -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")!))
Expand Down

0 comments on commit 6449969

Please sign in to comment.