modulepackage
0.4.2
Repository: https://github.com/spectrocloud-labs/herd.git
Documentation: pkg.go.dev
# README
:checkered_flag: herd
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"
}
# Functions
ConditionalOption defines an option that is enabled only if the conditional callback returns true.
DAG creates a new instance of a runnable Graph.
EnableIf defines an operation dependency.
IfElse defines options that are enabled if the condition passess or not It is just syntax sugar.
WithCallback associates a callback to the operation to be executed when the DAG is walked-by.
WithDeps defines an operation dependency.
WithWeakDeps defines dependencies that doesn't prevent the op to trigger.
# Variables
Background runs the operation in the background.
CollectOrphans enables orphan job collection.
EnableInit enables an Init jobs that takes paternity of orphan jobs without dependencies.
FatalOp makes the operation fatal.
No description provided by the author
WeakDeps sets all the dependencies of the job as "weak".
# Structs
Graph represents a directed graph.
GraphEntry is the external representation of the operation to execute (OpState).
No description provided by the author
# Type aliases
GraphOption it's the option for the DAG graph.
OpOption defines the operation settings.