Add ActivityCompleted notification for workflow activity completion (#6675)

* Initial plan for issue

* Add ActivityCompleted notification and send it when activity completes

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

* Prepare implementation plan for ActivityCompleted notification

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

* Move ActivityCompleted notification to NotificationPublishingMiddleware

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>
This commit is contained in:
Copilot 2025-05-24 23:01:41 +02:00 committed by GitHub
parent b9697a9e28
commit a2e65a235f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 1983 additions and 3 deletions

1942
dotnet-install.sh vendored Executable file

File diff suppressed because it is too large Load diff

View file

@ -5,7 +5,12 @@ using Elsa.Workflows.Pipelines.ActivityExecution;
namespace Elsa.Workflows.Middleware.Activities;
/// <summary>
/// An activity execution middleware component that publishes <see cref="ActivityExecuting"/> and <see cref="ActivityExecuted"/> events as an activity executes.
/// An activity execution middleware component that publishes activity notifications:
/// <list type="bullet">
/// <item><see cref="ActivityExecuting"/> when an activity starts executing</item>
/// <item><see cref="ActivityExecuted"/> when an activity has executed</item>
/// <item><see cref="Notifications.ActivityCompleted"/> when an activity transitions from Running to Completed status</item>
/// </list>
/// </summary>
public class NotificationPublishingMiddleware : IActivityExecutionMiddleware
{
@ -24,19 +29,31 @@ public class NotificationPublishingMiddleware : IActivityExecutionMiddleware
/// <inheritdoc />
public async ValueTask InvokeAsync(ActivityExecutionContext context)
{
// Store the status before execution
var statusBeforeExecution = context.Status;
// Send notification that activity is executing
await _notificationSender.SendAsync(new ActivityExecuting(context));
// Execute the activity
await _next(context);
// Send notification that activity has executed
await _notificationSender.SendAsync(new ActivityExecuted(context));
// Send notification that activity has completed if status transitioned from Running to Completed
if (statusBeforeExecution == ActivityStatus.Running && context.Status == ActivityStatus.Completed)
await _notificationSender.SendAsync(new Notifications.ActivityCompleted(context));
}
}
/// <summary>
/// Extends <see cref="IActivityExecutionPipelineBuilder"/> to install the <see cref="LoggingMiddleware"/> component.
/// Extends <see cref="IActivityExecutionPipelineBuilder"/> to install the <see cref="NotificationPublishingMiddleware"/> component.
/// </summary>
public static class NotificationPublishingMiddlewareExtensions
{
/// <summary>
/// Installs the <see cref="LoggingMiddleware"/> component.
/// Installs the <see cref="NotificationPublishingMiddleware"/> component.
/// </summary>
public static IActivityExecutionPipelineBuilder UseNotifications(this IActivityExecutionPipelineBuilder pipelineBuilder) => pipelineBuilder.UseMiddleware<NotificationPublishingMiddleware>();
}

View file

@ -0,0 +1,9 @@
using Elsa.Mediator.Contracts;
namespace Elsa.Workflows.Notifications;
/// <summary>
/// A notification that is sent when an activity has completed.
/// </summary>
/// <param name="ActivityExecutionContext">The activity execution context.</param>
public record ActivityCompleted(ActivityExecutionContext ActivityExecutionContext) : INotification;

2
tempvalidator/Program.cs Normal file
View file

@ -0,0 +1,2 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");

View file

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>