Skip to content

Releases: danielgerlag/workflow-es

Workflow ES 2.3

31 Mar 18:10
7097bc6
Compare
Choose a tag to compare

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

Workflow ES 2.2

25 Mar 22:06
63faf7e
Compare
Choose a tag to compare

Workflow ES 2.2

Parallel Sequences

Run several sequences of steps in parallel

class Parallel_Workflow {
    
    build(builder) {
        builder
        .startWith(SayHello)
        .parallel()
            .do(branch1 => branch1
                .startWith(PrintMessage)
                    .input((step, data) => step.message = "Running in branch 1")
                .delay(data => 5000)
                .then(DoSomething)
            )
            .do(branch2 => branch2
                .startWith(PrintMessage)
                    .input((step, data) => step.message = "Running in branch 2")
            )
            .do(branch3 => branch3
                .startWith(PrintMessage)
                    .input((step, data) => step.message = "Running in branch 3")
            )
        .join()
        .then(SayGoodbye);
    }
}

Workflow ES 2.1

25 Mar 00:53
c462c7b
Compare
Choose a tag to compare

Workflow ES 2.1

  • Fixed typescript 2.4 issue

  • Delay step

Put the workflow to sleep for a specifed number of milliseconds.

build(builder) {
    builder
        .startWith(HelloWorld)
        .delay(data => 2000)
        .then(GoodbyeWorld);
}
  • Schedule step

Schedule a sequence of steps to execution asynchronously in the future.

build(builder) {
    builder
        .startWith(HelloWorld)
        .schedule((data) => 20000).do((sequence) => sequence
            .startWith(DoSomething)
            .then(DoSomethingElse))
        .then(ContinueWithSomething);
}

2.0.1

17 Jun 13:20
Compare
Choose a tag to compare
Create README.md