-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9cf5181
commit 156d5bf
Showing
31 changed files
with
629 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Workflow Core 1.6.9 | ||
|
||
This release adds functionality to subscribe to workflow life cycle events (WorkflowStarted, WorkflowComplete, WorkflowError, WorkflowSuspended, WorkflowResumed, StepStarted, StepCompleted, etc...) | ||
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`. | ||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using WorkflowCore.Models.LifeCycleEvents; | ||
|
||
namespace WorkflowCore.Interface | ||
{ | ||
public interface ILifeCycleEventHub | ||
{ | ||
Task PublishNotification(LifeCycleEvent evt); | ||
void Subscribe(Action<LifeCycleEvent> action); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using WorkflowCore.Models.LifeCycleEvents; | ||
|
||
namespace WorkflowCore.Interface | ||
{ | ||
public interface ILifeCycleEventPublisher : IBackgroundTask | ||
{ | ||
void PublishNotification(LifeCycleEvent evt); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using WorkflowCore.Models; | ||
|
||
namespace WorkflowCore.Interface | ||
{ | ||
public interface IWorkflowErrorHandler | ||
{ | ||
WorkflowErrorHandling Type { get; } | ||
void Handle(WorkflowInstance workflow, WorkflowDefinition def, ExecutionPointer pointer, WorkflowStep step, Exception exception, Queue<ExecutionPointer> bubbleUpQueue); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace WorkflowCore.Models.LifeCycleEvents | ||
{ | ||
public abstract class LifeCycleEvent | ||
{ | ||
public DateTime EventTimeUtc { get; set; } | ||
|
||
public string WorkflowInsanceId { get; set; } | ||
|
||
public string WorkflowDefinitionId { get; set; } | ||
|
||
public int Version { get; set; } | ||
|
||
public string Reference { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace WorkflowCore.Models.LifeCycleEvents | ||
{ | ||
public class StepCompleted : LifeCycleEvent | ||
{ | ||
public string ExecutionPointerId { get; set; } | ||
|
||
public int StepId { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace WorkflowCore.Models.LifeCycleEvents | ||
{ | ||
public class StepStarted : LifeCycleEvent | ||
{ | ||
public string ExecutionPointerId { get; set; } | ||
|
||
public int StepId { get; set; } | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/WorkflowCore/Models/LifeCycleEvents/WorkflowCompleted.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace WorkflowCore.Models.LifeCycleEvents | ||
{ | ||
public class WorkflowCompleted : LifeCycleEvent | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace WorkflowCore.Models.LifeCycleEvents | ||
{ | ||
public class WorkflowError : LifeCycleEvent | ||
{ | ||
public string Message { get; set; } | ||
|
||
public string ExecutionPointerId { get; set; } | ||
|
||
public int StepId { get; set; } | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/WorkflowCore/Models/LifeCycleEvents/WorkflowResumed.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace WorkflowCore.Models.LifeCycleEvents | ||
{ | ||
public class WorkflowResumed : LifeCycleEvent | ||
{ | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/WorkflowCore/Models/LifeCycleEvents/WorkflowStarted.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace WorkflowCore.Models.LifeCycleEvents | ||
{ | ||
public class WorkflowStarted : LifeCycleEvent | ||
{ | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/WorkflowCore/Models/LifeCycleEvents/WorkflowSuspended.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace WorkflowCore.Models.LifeCycleEvents | ||
{ | ||
public class WorkflowSuspended : LifeCycleEvent | ||
{ | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/WorkflowCore/Models/LifeCycleEvents/WorkflowTerminated.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace WorkflowCore.Models.LifeCycleEvents | ||
{ | ||
public class WorkflowTerminated : LifeCycleEvent | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/WorkflowCore/Services/DefaultProviders/SingleNodeEventHub.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Logging; | ||
using WorkflowCore.Interface; | ||
using WorkflowCore.Models.LifeCycleEvents; | ||
|
||
namespace WorkflowCore.Services | ||
{ | ||
public class SingleNodeEventHub : ILifeCycleEventHub | ||
{ | ||
private ICollection<Action<LifeCycleEvent>> _subscribers = new HashSet<Action<LifeCycleEvent>>(); | ||
private readonly ILogger _logger; | ||
|
||
public SingleNodeEventHub(ILoggerFactory loggerFactory) | ||
{ | ||
_logger = loggerFactory.CreateLogger<SingleNodeEventHub>(); | ||
} | ||
|
||
public Task PublishNotification(LifeCycleEvent evt) | ||
{ | ||
Task.Run(() => | ||
{ | ||
foreach (var subscriber in _subscribers) | ||
{ | ||
try | ||
{ | ||
subscriber(evt); | ||
} | ||
catch (Exception ex) | ||
{ | ||
_logger.LogWarning(default(EventId), ex, $"Error on event subscriber: {ex.Message}"); | ||
} | ||
} | ||
}); | ||
return Task.CompletedTask; | ||
} | ||
|
||
public void Subscribe(Action<LifeCycleEvent> action) | ||
{ | ||
_subscribers.Add(action); | ||
} | ||
} | ||
} |
Oops, something went wrong.