Skip to content

Workflow ES 2.3

Latest
Compare
Choose a tag to compare
@danielgerlag danielgerlag released this 31 Mar 18:10
· 26 commits to master since this release
7097bc6

Workflow ES 2.3

Saga Transactions

Specifying compensation steps for each component of a saga transaction

In this sample, if Task2 throws an exception, then UndoTask2 and UndoTask1 will be triggered.

builder
    .startWith(SayHello)
        .compensateWith(UndoHello)
    .saga(saga => saga
        .startWith(Task1)
            .compensateWith(UndoTask1)
        .then(Task2)
            .compensateWith(UndoTask2)
        .then(Task3)
            .compensateWith(UndoTask3)
    )
    .then(SayGoodbye);

Retrying a failed transaction

This particular example will retry the entire saga every 5 seconds

builder
    .startWith(SayHello)
        .compensateWith(UndoHello)
    .saga(saga => saga
        .startWith(Task1)
	    .compensateWith(UndoTask1)
	.then(Task2)
	    .compensateWith(UndoTask2)
	.then(Task3)
	    .compensateWith(UndoTask3)
	)		
	.onError(WorkflowErrorHandling.Retry, 5000)
	.then(SayGoodbye);

Compensating the entire transaction

You could also only specify a master compensation step, as follows

builder
	.startWith(SayHello)
		.compensateWith(UndoHello)
	.saga(saga => saga
		.startWith(Task1)
		.then(Task2)
		.then(Task3)
	)		
    .compensateWithSequence(comp => comp
        .startWith(UndoTask1)
        .then(UndoTask2)
	    .then(UndoTask3)
    )
	.then(SayGoodbye);

Passing parameters

Parameters can be passed to a compensation step as follows

builder
    .startWith(SayHello)
    .compensateWith(PrintMessage, compensateStep => {
        compensateStep.input((step, data) => step.Message = "undoing...");
    });