Writing Tasks

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

A task is a Java/Kotlin class that:

  • must extend io.infinitic.tasks.Task abstract class
  • must have an empty constructor
  • have serializable methods parameters and return value
  • must be thread-safe

Beside that, it can contains arbitrary code. The Task abstract class is very simple, it contains only:

  • a context variable (maintained by Infinitic),
  • a getDurationBeforeRetry method, we can overide to describe how the task will react in case of failure

The other constraints are implied by the execution process: when receiving instructions to run a task, a task worker uses the empty constructor to instantiate the class, deserializes the parameters, executes the requested method and returns the serialized result. The class must be thread-safe to be run in parallel if we chose to.

Here is an example of task implementation, from our Hello World app:

import io.infinitic.tasks.Task;

public class HelloWorldServiceImpl extends Task implements HelloWorldService {
    @Override
    public String sayHello(String name) {

        return "Hello " + ((name == null) ? "World" : name);
    }

    @Override
    public String addEnthusiasm(String str) {

        return str + "!";
    }
}
import io.infinitic.tasks.Task

class HelloWorldServiceImpl: Task(), HelloWorldService {
    override fun sayHello(name: String) = "Hello $name"

    override fun addEnthusiasm(str: String) = "$str!"
}
Edit this page on GitHub Updated at Fri, May 28, 2021