Add Executing Activity event (#586)

This commit is contained in:
Bartlomiej Tadych 2021-01-25 12:16:29 +01:00 committed by GitHub
parent 2ad01ec023
commit d5b30b6044
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 1 deletions

View file

@ -122,6 +122,11 @@ namespace Elsa.Activities.ControlFlow.Activities
return $"@{sourceActivityId}_{sourceOutcomeName}";
}
public Task ExecutingActivityAsync(
WorkflowExecutionContext workflowExecutionContext,
IActivity activity,
CancellationToken cancellationToken) => Task.CompletedTask;
Task IWorkflowEventHandler.ActivityExecutedAsync(
WorkflowExecutionContext workflowContext,
IActivity activity,

View file

@ -9,6 +9,10 @@ namespace Elsa.Services
/// </summary>
public interface IWorkflowEventHandler
{
/// <summary>
/// Invoked before an activity execution.
/// </summary>
Task ExecutingActivityAsync(WorkflowExecutionContext workflowExecutionContext, IActivity activity, CancellationToken cancellationToken);
/// <summary>
/// Invoked when an activity has executed.

View file

@ -6,6 +6,15 @@ namespace Elsa.Services
{
public abstract class WorkflowEventHandlerBase : IWorkflowEventHandler
{
public Task ExecutingActivityAsync(
WorkflowExecutionContext workflowExecutionContext,
IActivity activity,
CancellationToken cancellationToken)
{
ExecutingActivity(workflowExecutionContext, activity);
return Task.CompletedTask;
}
public virtual Task ActivityExecutedAsync(
WorkflowExecutionContext workflowExecutionContext,
IActivity activity,
@ -41,6 +50,12 @@ namespace Elsa.Services
return Task.CompletedTask;
}
protected virtual void ExecutingActivity(
WorkflowExecutionContext workflowExecutionContext,
IActivity activity)
{
}
protected virtual void ActivityExecuted(WorkflowExecutionContext workflowExecutionContext, IActivity activity)
{
}

View file

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
@ -345,6 +345,11 @@ namespace Elsa.Services
IActivity activity,
CancellationToken cancellationToken)
{
await workflowEventHandlers.InvokeAsync(
async x => await x.ExecutingActivityAsync(workflowContext, activity, cancellationToken),
logger
);
return await InvokeActivityAsync(
workflowContext,
activity,