Documentation
¶
Overview ¶
Package rund implements a DAG task dependency scheduler.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CmdOperator ¶
type CmdOperator struct {
// contains filtered or unexported fields
}
CmdOperator runs external command.
func NewCmdOperator ¶
func NewCmdOperator(cmd []string, envar map[string]string) (CmdOperator, error)
NewCmdOperator returns a new CmdOperator.
type FuncOperator ¶
type FuncOperator func() error
FuncOperator executes function.
func NewFuncOperator ¶
func NewFuncOperator(f func() error) FuncOperator
NewFuncOperator returns a new FuncOperator.
type NoopOperator ¶
type NoopOperator struct{}
NoopOperator does nothing.
func NewNoopOperator ¶
func NewNoopOperator() NoopOperator
NewNoopOperator returns a new NoopOperator.
type Operator ¶
type Operator interface {
Run() error
}
Operator defines the Run interface to run operation.
type Rund ¶
type Rund struct {
// contains filtered or unexported fields
}
Rund adds `Operator` into the graph as node and edge, `Operator` runs in parallel topological order.
Example ¶
package main import ( "errors" "fmt" "github.com/andy2046/rund" ) func main() { r := rund.New() op1 := rund.NewFuncOperator(func() error { fmt.Println("1 will run before 2 and 3") return nil }) op2 := rund.NewFuncOperator(func() error { fmt.Println("2 and 3 will run in parallel before 4") return nil }) op3 := rund.NewFuncOperator(func() error { fmt.Println("2 and 3 will run in parallel before 4") return nil }) op4 := rund.NewFuncOperator(func() error { fmt.Println("4 will run after 2 and 3") return errors.New("4 is broken") }) op5 := rund.NewFuncOperator(func() error { fmt.Println("5 will never run") return nil }) r.AddNode("1", op1) r.AddNode("2", op2) r.AddNode("3", op3) r.AddNode("4", op4) r.AddNode("5", op5) r.AddEdge("1", "2") r.AddEdge("1", "3") r.AddEdge("2", "4") r.AddEdge("3", "4") r.AddEdge("4", "5") // 2 // / \ // 1 4 - 5 // \ / // 3 fmt.Printf("the result: %v\n", r.Run()) }
Output: 1 will run before 2 and 3 2 and 3 will run in parallel before 4 2 and 3 will run in parallel before 4 4 will run after 2 and 3 the result: 4 is broken
func (*Rund) AddEdge ¶
AddEdge establishes a dependency between two nodes in the graph, `from` node will be executed before `to` node.
Click to show internal directories.
Click to hide internal directories.