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.

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

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

Okay