Add input parameter to ScheduleChildActivity signal
This update includes adding an optional input parameter to the ScheduleChildActivity signal's constructor in order to pass options to the child activity. The input parameter is used while scheduling activities in FlowFork.cs and Flowchart.cs activities. This enables clearer data transfer and scheduling in the system.
This commit is contained in:
parent
18fd4ff796
commit
72b1b2bb40
|
|
@ -31,7 +31,7 @@ public class FlowFork : Activity
|
|||
/// <inheritdoc />
|
||||
protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)
|
||||
{
|
||||
var outcomes = Branches.GetOrDefault(context)?.ToArray() ?? new[] { "Done" };
|
||||
var outcomes = Branches.GetOrDefault(context)?.ToArray() ?? ["Done"];
|
||||
|
||||
await context.ScheduleOutcomesAsync(outcomes);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -298,11 +298,16 @@ public class Flowchart : Container
|
|||
{
|
||||
ExistingActivityExecutionContext = activityExecutionContext,
|
||||
CompletionCallback = OnChildCompletedAsync,
|
||||
Input = signal.Input
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
await flowchartContext.ScheduleActivityAsync(activity, OnChildCompletedAsync);
|
||||
await flowchartContext.ScheduleActivityAsync(activity, new ScheduleWorkOptions
|
||||
{
|
||||
CompletionCallback = OnChildCompletedAsync,
|
||||
Input = signal.Input
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
using Elsa.Workflows.Contracts;
|
||||
using Elsa.Workflows.Options;
|
||||
|
||||
namespace Elsa.Workflows.Signals;
|
||||
|
||||
|
|
@ -11,23 +12,32 @@ public class ScheduleChildActivity
|
|||
/// Signaled when the scheduling of a child activity was requested.
|
||||
/// </summary>
|
||||
/// <param name="activity">The child activity to schedule.</param>
|
||||
public ScheduleChildActivity(IActivity activity)
|
||||
/// <param name="input">Input to pass to the child activity.</param>
|
||||
public ScheduleChildActivity(IActivity activity, IDictionary<string, object>? input = default)
|
||||
{
|
||||
Activity = activity;
|
||||
Input = input;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Signaled when the scheduling of a child activity was requested.
|
||||
/// </summary>
|
||||
/// <param name="activityExecutionContext">The child activity execution context to schedule.</param>
|
||||
public ScheduleChildActivity(ActivityExecutionContext? activityExecutionContext)
|
||||
/// <param name="input">The scheduling options.</param>
|
||||
public ScheduleChildActivity(ActivityExecutionContext? activityExecutionContext, IDictionary<string, object>? input = default)
|
||||
{
|
||||
ActivityExecutionContext = activityExecutionContext;
|
||||
Input = input;
|
||||
}
|
||||
|
||||
/// <summary>The child activity to schedule.</summary>
|
||||
public IActivity? Activity { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Input to pass to the child activity.
|
||||
/// </summary>
|
||||
public IDictionary<string, object>? Input { get; set;}
|
||||
|
||||
/// <summary>
|
||||
/// The child activity execution context to schedule.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using Elsa.Workflows;
|
|||
using Elsa.Workflows.Attributes;
|
||||
using Elsa.Workflows.Models;
|
||||
using Elsa.Workflows.Options;
|
||||
using Elsa.Workflows.Signals;
|
||||
|
||||
namespace Elsa.Samples.AspNet.BatchProcessing.Activities;
|
||||
|
||||
|
|
@ -33,24 +34,17 @@ public class FetchProducts : CodeActivity<ICollection<Product>>
|
|||
var currentBatch = context.ActivityInput.TryGetValue(CurrentBathKey, out var currentBatchValue) ? (int)currentBatchValue : 0;
|
||||
var orders = GenerateProducts(count).Skip(currentBatch * batchSize).Take(batchSize).ToList();
|
||||
|
||||
Result.Set(context, orders);
|
||||
await context.CompleteActivityAsync();
|
||||
|
||||
if (orders.Any())
|
||||
{
|
||||
currentBatch++;
|
||||
context.SetProperty(CurrentBathKey, currentBatch);
|
||||
Result.Set(context, orders);
|
||||
|
||||
// Schedule the next batch.
|
||||
await context.ScheduleActivityAsync(this, new ScheduleWorkOptions
|
||||
{
|
||||
Input = new Dictionary<string, object>
|
||||
{
|
||||
[CurrentBathKey] = currentBatch
|
||||
}
|
||||
});
|
||||
await context.SendSignalAsync(new ScheduleChildActivity(this, new Dictionary<string, object> { [CurrentBathKey] = currentBatch }));
|
||||
}
|
||||
|
||||
// Complete the activity.
|
||||
await context.CompleteActivityAsync();
|
||||
}
|
||||
|
||||
private IEnumerable<Product> GenerateProducts(int count)
|
||||
|
|
|
|||
Loading…
Reference in a new issue