Add logging to OrderBatchProcessor workflow

Added a sequence with WriteLine activity to log processing of each order. Also, ensured the activity execution context properly sets its Tag property when a completion callback is provided.
This commit is contained in:
Sipke Schoorstra 2024-03-13 19:59:56 +01:00
parent 15518ba6db
commit e0a20c2dfc
2 changed files with 10 additions and 1 deletions

View file

@ -4,6 +4,7 @@ using Elsa.Samples.AspNet.BatchProcessing.Models;
using Elsa.Workflows;
using Elsa.Workflows.Activities;
using Elsa.Workflows.Contracts;
using Elsa.Workflows.Memory;
namespace Elsa.Samples.AspNet.BatchProcessing.Workflows;
@ -27,7 +28,14 @@ public class OrderBatchProcessor : WorkflowBase
},
new ParallelForEach<Order>
{
Items = new(orders)
Items = new(orders),
Body = new Sequence
{
Activities =
{
new WriteLine(context => $"Processing order {context.GetVariable<Order>("CurrentValue")!.Id}"),
}
}
},
new WriteLine("Done!")
}

View file

@ -278,6 +278,7 @@ public partial class ActivityExecutionContext : IExecutionContext
{
if (completionCallback != null)
{
Tag = options?.Tag;
var completedContext = new ActivityCompletedContext(this, this);
await completionCallback(completedContext);
}