DEV Community

orkes
orkes

Posted on

4 3 1 1 1

Go: Netflix Conductor Worker

What is Conductor

Conductor is a Microservices orchestration platform from Netflix, released under Apache 2.0 Open Source License.

Download and start Conductor server in 5 minutes

Quickstart

Install Golang package

go get github.com/netflix/conductor/client/go
Enter fullscreen mode Exit fullscreen mode

Implementing a Task a Worker

task package provides the types used to implement the worker. Here is a reference worker implementation:

package task

import (
    "fmt"
)

// Implementation for "task_1"
func Task_1_Execution_Function(t *task.Task) (taskResult *task.TaskResult, err error) {
    log.Println("Executing Task_1_Execution_Function for", t.TaskType)

    //Do some logic
    taskResult = task.NewTaskResult(t)

    output := map[string]interface{}{"task":"task_1", "key2":"value2", "key3":3, "key4":false}
    taskResult.OutputData = output
    taskResult.Status = "COMPLETED"
    err = nil

    return taskResult, err
}
Enter fullscreen mode Exit fullscreen mode

Worker Polling

Here is an example that shows how to start polling for tasks after defining the tasks.

package main

import (
    "github.com/netflix/conductor/client/go"
    "github.com/netflix/conductor/client/go/task/sample"
)

func main() {
    c := conductor.NewConductorWorker("http://localhost:8080", 1, 10000)

    c.Start("task_1", "", sample.Task_1_Execution_Function, false)
    c.Start("task_2", "mydomain", sample.Task_2_Execution_Function, true)
}
Enter fullscreen mode Exit fullscreen mode

NewConductorWoker parameters

  1. baseUrl: Server address.
  2. threadCount: No. of threads. Number of threads should be at-least same as the number of workers
  3. pollingInterval: Time in millisecond between subsequent polls

See
https://github.com/Netflix/conductor/tree/main/polyglot-clients/go
for the source code and follow us on GitHub for updates.

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay