Writing Workflows

Infinitic is still in active development. Subscribe here to follow the progress.

Here are an example of workflow implementation, from our Hello World app:

import hello.world.tasks.HelloWorldService;
import io.infinitic.workflows.Workflow;

public class HelloWorldImpl extends Workflow implements HelloWorld {
    private final HelloWorldService helloWorldService = task(HelloWorldService.class);

    @Override
    public String greet(String name) {
        String str = helloWorldService.sayHello(name);
        String greeting =  helloWorldService.addEnthusiasm(str);
        inline(() -> { System.out.println(greeting); return null; });

        return greeting;
    }
}
import hello.world.tasks.HelloWorldService
import io.infinitic.workflows.Workflow
import io.infinitic.workflows.task

class HelloWorldImpl : Workflow(), HelloWorld {
    private val helloWorldService = task<HelloWorldService>()

    override fun greet(name: String?): String {
        val str = helloWorldService.sayHello(name)
        val greeting =  helloWorldService.addEnthusiasm(str)
        inline { println(greeting) }

        return  greeting
    }
}

As we can see above, a workflow is directly coded in plain java/kotlin - but the processing of this workflow is actually event-based, making Infinitic scalable and error-resilient.

If you are interested how it works, please read under the hood of a event-driven workflow engine.

Basically, at each step, the state of the workflow is automaticaly saved, including the status (runnning, completed...) and output of previous steps. When something happens relevant to this workflow - for example a task completion - the workflow is processed again from the start, but the saved history is automaticaly used to skip everything already done.

The workflow implementation must contain only the deterministic description of the flow of tasks.

A workflow class must

  • extend io.infinitic.workflows.Workflow
  • be public and have an empty constructor
  • have serializable parameters and return value for its methods

and be deterministic, without side effects, so:

  • database request
  • file access
  • API call
  • environment variables
  • current date
  • random values
  • multi-threads

must not be used in workflows, but can and must be implemented in tasks.

Edit this page on GitHub Updated at Fri, May 28, 2021