/examples-go

Examples of workflows implemented in Golang using Zenaton

Primary LanguageGo

⚠️ This repository is abandoned.

Zenaton examples for Go

This repository contains examples of workflows built with Zenaton. These examples illustrates how Zenaton orchestrates tasks that are executed on different workers.

Installation

Download this repo

go get github.com/zenaton/examples-go

and the client library

go get github.com/zenaton/zenaton-go/...

cd into example directory

cd $(go env GOPATH)/src/github.com/zenaton/examples-go

then add an .env file

cp -n .env.example .env

and populate it with your application id and api token found here.

Running Locally

Then, you need to install a Zenaton worker

curl https://install.zenaton.com | sh

and make it listen to your configuration:

zenaton listen --boot=boot/boot.go

Your all set!

Your workflows will be processed by your worker, so you won't see anything except the stdout and stderr, respectively zenaton.out and zenaton.err. Look at these files :)

Example 1 : Sequential tasks execution

This example showcases

  • a sequential execution of three tasks. The second and third tasks are executed only when the previous one is processed.
  • In a sequential task execution, you can get the output of a task. The result of a task can be used by the next one.

Sequential Workflow Diagram

go run sequential/main.go

Example 2: Parallel tasks execution

This example showcases

  • a parallel execution of 2 tasks
  • a third task that is executed only after both first two tasks were processed

Parallel Workflow Diagram

go run parallel/main.go

Example 3: Asynchronous tasks execution

this example showcases

  • Asynchronous executions of Task A and Task B (fire and forget)
  • Then sequential executions of Task C and Task D

Asynchronous Workflow Diagram

go run asynchronous/main.go

When a task is dispatched asynchronously, the workflow continues its execution without waiting for the task completion. Consequently, a task asynchronous dispatching does not return a value from the task.

Example 4: Event

This example showcases

  • how to change a workflow's behaviour based on an external event

Event Workflow Diagram

go run event/main.go

Example 5: Wait

This example showcases

  • how the provided Wait task can be used to pause the workflow for a specified duration

Wait Workflow Diagram

go run wait/main.go

Example 6: Wait Event

This example showcases

  • how the provided Wait task can also be used to pause the workflow up to receiving a specific external event

WaitEvent Workflow Diagram

go run waitevent/main.go

Example 7: Error Workflow

This example showcases

  • how to recover from a faulty task

Error Workflow Diagram

go run error/main.go

Example 7: Recursive Workflow

This example showcases

  • how launching events or workflows directly from orchestrated tasks allows you to schedule recurring workflows
go run recursive/main.go

Example 8: Workflow Versions

This example showcases

  • how to update your workflow implementation, even while previous versions are still running
go run version/main.go