Skip to content

defining workflow

Mahmoud Ben Hassine edited this page Jul 17, 2017 · 12 revisions

The WorkFlow API

A work flow in Easy Flows is represented by the WorkFlow interface:

public interface WorkFlow extends Work {

}

A workflow is also a work. This what makes workflows composable.

Built-in flows

Easy Flows comes with 4 implementations of the WorkFlow interface:

Conditional flow

A conditional flow is defined by 4 artifacts:

  • The work to execute first
  • A WorkReportPredicate for the conditional logic
  • The work to execute if the predicate is satisfied
  • The work to execute if the predicate is not satisfied (optional)

To create a ConditionalFlow, you can use the ConditionalFlow.Builder :

ConditionalFlow conditionalFlow = ConditionalFlow.Builder.aNewConditionalFlow()
        .named("my conditional flow")
        .execute(work1)
        .when(WorkReportPredicate.COMPLETED)
        .then(work2)
        .otherwise(work3)
        .build();

Sequential flow

A SequentialFlow, as its name implies, executes a set of work units in sequence. If a work fails, next works in the pipeline will be skipped. To create a SequentialFlow , you can use the SequentialFlow.Builder :

SequentialFlow sequentialFlow = SequentialFlow .Builder.aNewSequentialFlow()
        ..named("execute 'work1', 'work2' and 'work3' in sequence")
        .execute(work1)
        .then(work2)
        .then(work3)
        .build();

Parallel flow

A parallel flow executes a set of works in parallel. The status of a parallel flow execution is defined as:

  • WorkStatus#COMPLETED : If all works have successfully completed
  • WorkStatus#FAILED : If one of the works has failed

To create a ParallelFlow, you can use the ParallelFlow.Builder :

ParallelFlow parallelFlow = ParallelFlow .Builder.aNewParallelFlow()
        .named("execute 'work1', 'work2' and 'work3' in parallel")
        .execute(work1, work2, work3)
        .build();

Repeat flow

A RepeatFlow executes a given work in loop until a condition becomes true or for a fixed number of times. The condition is expressed using a WorkReportPredicate. To create a RepeatFlow , you can use the RepeatFlow.Builder :

RepeatFlow repeatFlow = RepeatFlow .Builder.aNewRepeatFlow()
        .named("execute work 3 times")
        .repeat(work)
        .times(3)
        .build();

// or

RepeatFlow repeatFlow = RepeatFlow .Builder.aNewRepeatFlow()
        .named("execute work forever!")
        .repeat(work)
        .until(WorkReportPredicate.ALWAYS_TRUE)
        .build();

Those are the basic flows you need to know to start creating workflows with Easy Flows. You don't need to learn a complex notation or concepts, just a few natural APIs that are easy to think about.

Creating custom flows

You can create your own flows by implementing the WorkFlow interface. The WorkFlowEngine works against interfaces, so your implementation should be interoperable with built-in flows without any issue.

Clone this wiki locally