workflow-core icon indicating copy to clipboard operation
workflow-core copied to clipboard

SAGA Compensation - End Step not executed

Open weismantelf opened this issue 3 years ago • 1 comments

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 avatar Dec 02 '21 13:12 weismantelf

@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"));
    }

potatopeelings avatar Dec 20 '21 01:12 potatopeelings