Documentation ¶
Index ¶
- type Graph
- type GraphEntry
- type GraphOption
- type OpOption
- func ConditionalOption(condition func() bool, op OpOption) OpOption
- func EnableIf(conditional func() bool) OpOption
- func IfElse(condition bool, op, noOp OpOption) OpOption
- func WithCallback(fn ...func(context.Context) error) OpOption
- func WithDeps(deps ...string) OpOption
- func WithWeakDeps(deps ...string) OpOption
- type OpState
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Graph ¶
Graph represents a directed graph.
func DAG ¶
func DAG(opts ...GraphOption) *Graph
DAG creates a new instance of a runnable Graph. A DAG is a Direct Acyclic Graph. The graph is walked, and depending on the dependencies it will run the jobs as requested. The Graph can be explored with `Analyze()`, extended with new operations with Add(), and finally being run with Run(context.Context).
func (*Graph) Add ¶
Add adds a new operation to the graph. Requires a name (string), and accepts a list of options.
func (*Graph) Analyze ¶
func (g *Graph) Analyze() (graph [][]GraphEntry)
Analyze returns the DAG and the Graph in the execution order. It will also return eventual updates if called after Run().
func (*Graph) Run ¶
Run starts the jobs defined in the DAG with a context. It returns error in case of failure.
func (*Graph) State ¶
func (g *Graph) State(name string) GraphEntry
Stage returns the DAG item state. Note: it locks to be thread-safe.
type GraphEntry ¶
type GraphEntry struct { WithCallback bool Background bool Callback []func(context.Context) error Error error Ignored, Fatal, WeakDeps, Executed bool Name string Dependencies []string WeakDependencies []string }
GraphEntry is the external representation of the operation to execute (OpState).
type GraphOption ¶
type GraphOption func(g *Graph)
GraphOption it's the option for the DAG graph.
var CollectOrphans GraphOption = func(g *Graph) { g.collectOrphans = true }
CollectOrphans enables orphan job collection.
var EnableInit GraphOption = func(g *Graph) { g.init = true }
EnableInit enables an Init jobs that takes paternity of orphan jobs without dependencies.
type OpOption ¶
OpOption defines the operation settings.
var Background OpOption = func(key string, os *OpState, g *Graph) error { os.background = true return nil }
Background runs the operation in the background.
FatalOp makes the operation fatal. Any error will make the DAG to stop and return the error immediately.
WeakDeps sets all the dependencies of the job as "weak". Any failure of the jobs which depends on won't impact running the job. By default, a failure job will make also fail all the children - this is option disables this behavor and make the child start too.
func ConditionalOption ¶ added in v0.2.1
ConditionalOption defines an option that is enabled only if the conditional callback returns true.
func EnableIf ¶ added in v0.4.0
EnableIf defines an operation dependency. Dependencies can be expressed as a string. Note: before running the DAG you must define all the operations.
func IfElse ¶ added in v0.4.0
IfElse defines options that are enabled if the condition passess or not It is just syntax sugar.
func WithCallback ¶
WithCallback associates a callback to the operation to be executed when the DAG is walked-by.
func WithDeps ¶
WithDeps defines an operation dependency. Dependencies can be expressed as a string. Note: before running the DAG you must define all the operations.
func WithWeakDeps ¶ added in v0.4.1
WithWeakDeps defines dependencies that doesn't prevent the op to trigger.