Skip to content

Commit 156d5bf

Browse files
authored
Workflow life cycle events (danielgerlag#215)
1 parent 9cf5181 commit 156d5bf

31 files changed

+629
-111
lines changed

ReleaseNotes/1.6.9.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Workflow Core 1.6.9
2+
3+
This release adds functionality to subscribe to workflow life cycle events (WorkflowStarted, WorkflowComplete, WorkflowError, WorkflowSuspended, WorkflowResumed, StepStarted, StepCompleted, etc...)
4+
This can be achieved by either grabbing the `ILifeCycleEventHub` implementation from the IoC container and subscribing to events there, or attach an event on the workflow host class `IWorkflowHost.OnLifeCycleEvent`.
5+
This implementation only publishes events to the local node... we will still need to implement a distributed version of the EventHub to solve the problem for multi-node clusters.

WorkflowCore.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ReleaseNotes", "ReleaseNote
9393
ReleaseNotes\1.6.0.md = ReleaseNotes\1.6.0.md
9494
ReleaseNotes\1.6.6.md = ReleaseNotes\1.6.6.md
9595
ReleaseNotes\1.6.8.md = ReleaseNotes\1.6.8.md
96+
ReleaseNotes\1.6.9.md = ReleaseNotes\1.6.9.md
9697
EndProjectSection
9798
EndProject
9899
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WorkflowCore.Sample14", "src\samples\WorkflowCore.Sample14\WorkflowCore.Sample14.csproj", "{6BC66637-B42A-4334-ADFB-DBEC9F29D293}"

src/WorkflowCore/Interface/IExecutionResultProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace WorkflowCore.Interface
55
{
66
public interface IExecutionResultProcessor
77
{
8-
void HandleStepException(WorkflowInstance workflow, WorkflowDefinition def, ExecutionPointer pointer, WorkflowStep step);
8+
void HandleStepException(WorkflowInstance workflow, WorkflowDefinition def, ExecutionPointer pointer, WorkflowStep step, Exception exception);
99
void ProcessExecutionResult(WorkflowInstance workflow, WorkflowDefinition def, ExecutionPointer pointer, WorkflowStep step, ExecutionResult result, WorkflowExecutorResult workflowResult);
1010
}
1111
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.Threading.Tasks;
5+
using WorkflowCore.Models.LifeCycleEvents;
6+
7+
namespace WorkflowCore.Interface
8+
{
9+
public interface ILifeCycleEventHub
10+
{
11+
Task PublishNotification(LifeCycleEvent evt);
12+
void Subscribe(Action<LifeCycleEvent> action);
13+
}
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using WorkflowCore.Models.LifeCycleEvents;
5+
6+
namespace WorkflowCore.Interface
7+
{
8+
public interface ILifeCycleEventPublisher : IBackgroundTask
9+
{
10+
void PublishNotification(LifeCycleEvent evt);
11+
}
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using WorkflowCore.Models;
5+
6+
namespace WorkflowCore.Interface
7+
{
8+
public interface IWorkflowErrorHandler
9+
{
10+
WorkflowErrorHandling Type { get; }
11+
void Handle(WorkflowInstance workflow, WorkflowDefinition def, ExecutionPointer pointer, WorkflowStep step, Exception exception, Queue<ExecutionPointer> bubbleUpQueue);
12+
}
13+
}

src/WorkflowCore/Interface/IWorkflowHost.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System;
33
using System.Threading.Tasks;
44
using WorkflowCore.Models;
5+
using WorkflowCore.Models.LifeCycleEvents;
56

67
namespace WorkflowCore.Interface
78
{
@@ -19,6 +20,7 @@ public interface IWorkflowHost : IWorkflowController
1920

2021

2122
event StepErrorEventHandler OnStepError;
23+
event LifeCycleEventHandler OnLifeCycleEvent;
2224
void ReportStepError(WorkflowInstance workflow, WorkflowStep step, Exception exception);
2325

2426
//public dependencies to allow for extension method access
@@ -32,4 +34,5 @@ public interface IWorkflowHost : IWorkflowController
3234
}
3335

3436
public delegate void StepErrorEventHandler(WorkflowInstance workflow, WorkflowStep step, Exception exception);
35-
}
37+
public delegate void LifeCycleEventHandler(LifeCycleEvent evt);
38+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace WorkflowCore.Models.LifeCycleEvents
6+
{
7+
public abstract class LifeCycleEvent
8+
{
9+
public DateTime EventTimeUtc { get; set; }
10+
11+
public string WorkflowInsanceId { get; set; }
12+
13+
public string WorkflowDefinitionId { get; set; }
14+
15+
public int Version { get; set; }
16+
17+
public string Reference { get; set; }
18+
}
19+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace WorkflowCore.Models.LifeCycleEvents
6+
{
7+
public class StepCompleted : LifeCycleEvent
8+
{
9+
public string ExecutionPointerId { get; set; }
10+
11+
public int StepId { get; set; }
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace WorkflowCore.Models.LifeCycleEvents
6+
{
7+
public class StepStarted : LifeCycleEvent
8+
{
9+
public string ExecutionPointerId { get; set; }
10+
11+
public int StepId { get; set; }
12+
}
13+
}

0 commit comments

Comments
 (0)