workflow-core
workflow-core copied to clipboard
SAGA Compensation - End Step not executed
Hello,
I have a question to the SAGA workflow. I am using the following sample:
public void Build(IWorkflowBuilder<object> builder)
{
builder
.StartWith(context => Console.WriteLine("Begin"))
.Saga(saga => saga
.StartWith<Task1>()
.CompensateWith<UndoTask1>()
.Then<Task2>()
.CompensateWith<UndoTask2>()
.Then<Task3>()
)
.Then(context => Console.WriteLine("End"));
}
The output for this sample is:
Starting workflow...
Begin
Doing Task 1
Doing Task 2
Undoing Task 2
Undoing Task 1
I expected that the last step ".Then(context => Console.WriteLine("End"));" will be executed.
When I am using the Compensate of an entire saga transaction, then the last step is called.
Do I something wrong ?
@weismantelf it will call the last step if you add a saga level CompensateWith
(even if you have nothing to do in it)
public void Build(IWorkflowBuilder<object> builder)
{
builder
.StartWith(context => Console.WriteLine("Begin"))
.Saga(saga => saga
.StartWith<Task1>()
.CompensateWith<UndoTask1>()
.Then<Task2>()
.CompensateWith<UndoTask2>()
.Then<Task3>()
)
.CompensateWith(_ => {}) // new line
.Then(context => Console.WriteLine("End"));
}