Documentation ¶
Overview ¶
Package dag - Lightweight Directed Acyclic Graph (DAG) Build System.
It allows building a list of tasks and then running the tasks in different DAG trees.
The tree dependencies are calculated and tasks that have met their dependencies are run in parallel. Max parallelism can be set and there is an option to run it serially for cases where user interaction is required.
Index ¶
- Variables
- func Stderr(ctx context.Context) io.Writer
- func Stdout(ctx context.Context) io.Writer
- type ContextKey
- type Errors
- type Graph
- func (g *Graph) AddTask(t *Task)
- func (g *Graph) DepthFirstSort() ([]*Vertex, error)
- func (g *Graph) Run(ctx context.Context, opt *getoptions.GetOpt, args []string) error
- func (g *Graph) SetMaxParallel(max int) *Graph
- func (g *Graph) SetOutputBuffer(w io.Writer) *Graph
- func (g *Graph) SetSerial() *Graph
- func (g *Graph) String() string
- func (g *Graph) Task(id string) *Task
- func (g *Graph) TaskDependensOn(t *Task, tDependencies ...*Task)
- func (g *Graph) Validate(tm *TaskMap) error
- type ID
- type Task
- type TaskMap
- type Vertex
Constants ¶
This section is empty.
Variables ¶
var ( ErrorTaskNil = fmt.Errorf("nil task given") ErrorTaskID = fmt.Errorf("missing task ID") ErrorTaskFn = fmt.Errorf("missing task function") ErrorTaskDuplicate = fmt.Errorf("task definition already exists") ErrorTaskNotFound = fmt.Errorf("task not found") ErrorTaskDependencyDuplicate = fmt.Errorf("task dependency already defined") ErrorGraphHasCycle = fmt.Errorf("graph has a cycle") ErrorTaskSkipped = fmt.Errorf("skipped") )
var ErrorSkipParents = fmt.Errorf("skip parents without failing")
ErrorSkipParents - Allows for conditional tasks that allow a task to Skip all parent tasks without failing the run
Functions ¶
Types ¶
type ContextKey ¶ added in v0.24.0
type ContextKey string
type Graph ¶
type Graph struct { Name string TickerDuration time.Duration Vertices map[ID]*Vertex // contains filtered or unexported fields }
func (*Graph) DepthFirstSort ¶ added in v0.24.0
DepthFirstSort - Returns a sorted list with the Vertices https://en.wikipedia.org/wiki/Topological_sorting#Depth-first_search It returns ErrorGraphHasCycle is there are cycles.
func (*Graph) Run ¶
Run - Execute the graph tasks in parallel where possible. It checks for tasks updates every 1 Millisecond by default. Modify using the graph.TickerDuration
func (*Graph) SetMaxParallel ¶ added in v0.24.0
SetMaxParallel - Limit concurrency.
func (*Graph) SetOutputBuffer ¶ added in v0.24.0
SetOutputBuffer - Adds a buffer in the context passed to the task that allows the task logging to be sent to that buffer. At the end of the task, the in memory buffered output will be written to the given io.Writer.
The context keys are 'StdoutBuffer' and 'StderrBuffer' which can be retrieved with the helper functions. The helper functions default to os.Stdout and os.Stderr when no buffering is defined.
g.SetOutputBuffer(os.Stdout) stdout := dag.Stdout(ctx) stderr := dag.Stderr(ctx) fmt.Fprintf(stdout, "Output") fmt.Fprintf(stderr, "Error")
NOTE: Even though both stdout and stderr contex keys are provided, currently both are combined into a single output and written into the given io.Writer.
func (*Graph) SetSerial ¶
SetSerial - The call to Run() will run the Tasks serially. Useful when the tasks require user input and the user needs to see logs in order to make a decision.
func (*Graph) TaskDependensOn ¶
TaskDependensOn - Allows adding tasks to the graph and defining their edges.
type Task ¶
type Task struct { ID ID Fn getoptions.CommandFn // contains filtered or unexported fields }
type TaskMap ¶
type TaskMap struct {
// contains filtered or unexported fields
}
func (*TaskMap) Add ¶
Add - Adds a new task to the TaskMap. Errors collected for TaskMap.Validate().