elsa-workflows / elsa-core

A .NET workflows library
https://v3.elsaworkflows.io/
MIT License
6.26k stars 1.15k forks source link

Revise Workflow Runner with Chain of Command strategy #1222

Open sfmskywalker opened 3 years ago

sfmskywalker commented 3 years ago

Currently, the WorkflowRunner publishes a bunch of notifications (using MediatR) at various stages of activity execution. A great advantage of this is that many aspects of workflow execution become decoupled. For example, persisting workflow instances after a burst of execution is handled by a notification handler.

But this implementation also poses some challenges. The biggest one being unable to control the order in which event handlers execute for the same event as discussed in #1204.

This is a clear sign that the event model isn't the most appropriate one for handling key-workflow engine steps. Instead, a Chain of Command strategy seems more appropriate to orchestrate key-steps, since it allows not only extensibility of the workflow processing, but also the order in which they occur.

We will still keep publishing notifications from the workflow runner, but these would be handled by (optional) handlers.

tomy2105 commented 3 years ago

We will still keep publishing notifications from the workflow runner, but these would be handled by (optional) handlers.

Glad to hear this since I just wrote one big handler to bunch of workflow notifications writing stuff to logs and publishin execution metrics to external system :)

sfmskywalker commented 3 years ago

Yes, that’s exactly the kind of thing events will stick around for :)