...
Asynchronous execution
Stage execution in sequence
Stage execution in parallel
Complex flow execution, including execution of nested flows in parallel
Dynamic stage generation based on context data
Stage cancellation of one of the upstream stages failed
Stage execution observability
methods to observe critical moments of stage execution
explicit logging, including flow engine reports in logs
Java-friendly context management using the Decorator pattern
Expand | |||||
---|---|---|---|---|---|
| |||||
|
Sequence Task Execution
Description
...
Info |
---|
Data can be transferred between stages using StageContext model. Stage context store data with key as |
Drawio sketch | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
...
When one of the stages in flow fails - the flow manager stops the execution and calls onFlowErrorStage
(if defined)
Drawio sketch | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
...
Drawio sketch | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Code Block | ||
---|---|---|
| ||
Flow.builder() .id("Simple Flow") .stage(task1) .stage(task2) .stage(task3) .stage(task4) .onFlowCancellation(onFlowCancellationStage)/ta .onFlowError(onFlowErrorStage) .executionStrategy(CANCEL_ON_ERROR | IGNORE_ON_ERROR) .build(); |
Parallel Task Execution
...
Parallel Stage execution
Drawio sketch | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
...
Info | |||||
---|---|---|---|---|---|
Note that parallelism is customizable by defining an executor when building
|
Parallel Stage execution(stage failed)
Drawio sketch | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Code Block | ||
---|---|---|
| ||
Flow.builder()
.id("Simple Flow")
.stage(task1)
.stage(ParallelStage.of(task2_1, task2_2, task2_3))
.stage(task3)
.onFlowError(onFlowErrorStage)
.build(); |
Parallel Stage execution (stage failed with cancellation)
Drawio sketch | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Code Block | ||
---|---|---|
| ||
Flow.builder()
.id("Simple Flow")
.stage(task1)
.stage(ParallelStage.of(task2_1, task2_2, task2_3))
.stage(task3)
.onFlowCancellation(onFlowCancellationStage)
.executionStrategy(CANCEL_ON_ERROR)
.build(); |
Nested flow execution
Drawio sketch | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Code Block | ||
---|---|---|
| ||
var flow1 = Flow.builder() .id("Flow 1") .stage(task2_1_1) .stage(task2_1_2) .build(); var flow2 = Flow.builder() .id("Flow 1") .stage(task2_2_1) .stage(task2_2_2) .build(); Flow.builder() .id("Simple Flow") .stage(task1) .stage(ParallelStage.of(flow1, flow2)) .stage(task3) .build(); |
Interfaces and models
Flow / Flow Builder
Provides a Flow
object, containing a sequence of stages and flows to be executed
Sucessfull flow executions are always finished without exceptions
If error is occurred during flow execution and
executionStrategy
isIGNORE_ON_ERROR
- thenFlowExecutionException
will be raised with a reason in causeIf error is occurred during flow execution and
executionStrategy
isCANCEL_ON_ERROR
- thenFlowCancelledException
will be raised with a reason of cancellation in causeFlowCancellationException
will be raised with a reason of cancellation failure in cause
Flows can be executed in async mode using flowEngine.executeAsync
method. In this case result in CompletableFuture
will contain an exception in the body.
Method | Description |
---|---|
| Used to define flow identifier that will be used for report and in the trace logs |
| Allows to define a |
| Allows to define a general flow parameter that will be available for all stages in the flow |
| Allow to define a map with flow parameters that will be available for all stages in the flow |
| Allows to define flow execution strategy:
|
...
| |||
| Allows to define a | ||
| Allows to define a | ||
| Allows to define a | ||
| Allows to define a
|
Flow Engine
A flow engine is an object that is used to execute a flow defined by a developer
Method | Description |
---|---|
| Executes flow using executor and timeout from |
| Executes flow using executor and timeout from |
| Allows to get flow status from Posible flow statuses:
|
| Provides a |
Builder
Flow engine builder allows to customize a FlowEngine
object
Method | Description |
---|---|
| Executes flow using executor and timeout from |
| Executes flow using executor and timeout from |
| Allows to get flow status from Posible flow statuses:
|
| Provides a |
Stage
This interface is functional, which means that it can be used as lambda for stage definition
Code Block | ||
---|---|---|
| ||
var stage1 = new Stage<>() {
@Override
public void execute(StageContext context) {
System.out.println("Stage executed");
}
};
var stage2 = (Stage<StageContext>) context -> System.out.println("Stage2 executed");
Flow.builder()
.id("Simple Flow")
.stage(stage1)
.stage(stage2)
.stage(context -> System.out.println("Stage3 executed"))
.build(); |
Models
Stage
Flow
...
Note |
---|
The limitation of using lambdas - it’s their nature in Java and this approach won’t allow to determine in information about generic type, so context customization is not working with this case, and raw StageContext will be passed |
Flow Methods
The flow engine uses flow methods to determine, what capabilities the stage provides:
Stage cancellation
Stage recovery
Method | Description |
---|---|
| Main method, which is must be defined for stage with business logic |
| Returns stage identifier, which will be printed in the final report or in listenable methods |
| Provides the ability to recover a stage after fail in |
| Provides an ability to revert changed, done in |
| Defines execution of |
Listenable Methods
Listenable methods provided at crucial points of stage execution to provide better observability for the stage execution status
Method | Description |
---|---|
| This method is called before stage execution |
| This method is called after successful stage execution including successful execution of |
| This method is called after unsuccessful stage execution ( |
| This method is called after successful execution of |
| This method is called after unsuccessful execution of |