DEV Community

dtnf45 for orkes

Posted on • Updated on

Task Workers in Netflix Conductor - Orkes

A worker is responsible for executing a task. Operator and System tasks are handled by the Conductor server, while user defined tasks needs to have a worker created that awaits the work to be scheduled by the server for it to be executed. Workers can be implemented in any language, and Conductor provides support for Java, Golang and Python worker framework that provides features such as polling threads, metrics and server communication that makes creating workers each.

Each worker embodies Microservice design pattern and follows certain basic principles:

Workers are stateless and do not implement a workflow specific logic.

Each worker executes a very specific task and produces well defined output given specific inputs.

Workers are meant to be idempotent (or should handle cases where the task that partially executed gets rescheduled due to timeouts etc.)

Workers do not implement the logic to handle retries etc, that is taken care by the Conductor server.

Implementing a Task Worker

To create a worker, implement the Worker interface.

public class SampleWorker implements Worker {

    private final String taskDefName;

    public SampleWorker(String taskDefName) {
        this.taskDefName = taskDefName;
    }

    @Override
    public String getTaskDefName() {
        return taskDefName;
    }

    @Override
    public TaskResult execute(Task task) {
        TaskResult result = new TaskResult(task);
        result.setStatus(Status.COMPLETED);

        //Register the output of the task
        result.getOutputData().put("outputKey1", "value");
        result.getOutputData().put("oddEven", 1);
        result.getOutputData().put("mod", 4);

        return result;
    }
}
Enter fullscreen mode Exit fullscreen mode

More Details

https://orkes.io/content/docs/how-tos/task-configurations

Follow and star us on GitHub for updates
https://github.com/Netflix/conductor/

Join the Slack Community Channel at
https://join.slack.com/t/orkes-conductor/shared_invite/zt-xyxqyseb-YZ3hwwAgHJH97bsrYRnSZg

Top comments (0)