Skip to content

spectrocloud-labs/herd

Repository files navigation

🏁 herd

Go Reference Lint Unit tests

Herd is a Embedded Runnable DAG (H.E.R.D.). it aims to be a tiny library that allows to define arbitrary DAG, and associate job operations on them.

Why?

I've found couple of nice libraries (fx, or dag for instance), however none of them satisfied my constraints:

  • Tiny
  • Completely tested (TDD)
  • Define jobs in a DAG, runs them in sequence, execute the ones that can be done in parallel (parallel topological sorting) in separate go routines
  • Provide some sorta of similarity with systemd concepts

Usage

herd can be used as a library as such:

package main

import (
    "context"

    "github.com/spectrocloud-labs/herd"
)

func main() {

    // Generic usage
    g := herd.DAG()
    g.Add("name", ...)
    g.Run(context.TODO())

    // Example
    f := ""
    g.Add("foo", herd.WithCallback(func(ctx context.Context) error {
        f += "foo"
        // This executes after "bar" has ended successfully.
        return nil
    }), herd.WithDeps("bar"))

    g.Add("bar", herd.WithCallback(func(ctx context.Context) error {
        f += "bar"
        // This execute first
        return nil
    }))

    // Execute the DAG
    g.Run(context.Background())
    // f is "barfoo"
}

About

🏁 Herd - Herd is an Embeddable Runnable DAG

Resources

License

Stars

Watchers

Forks

Packages

No packages published