Documentation ¶
Index ¶
- Variables
- func NopeWalker(_ Node) error
- type DepTask
- type FuncScheduler
- type Graph
- type Injector
- type InjectorFactory
- type InjectorFactoryFunc
- type Named
- type Node
- type Registry
- type Scheduler
- func (d *Scheduler[T]) CancelWithErr(err error)
- func (d *Scheduler[T]) Dot() string
- func (d *Scheduler[T]) Run(ctx context.Context, x T) error
- func (d *Scheduler[T]) Submit(tasks ...Task[T]) error
- func (d *Scheduler[T]) SubmitFunc(name string, f func(context.Context, T) error, deps ...string) error
- func (d *Scheduler[T]) WithInjectorFactory(injectFac InjectorFactory[T]) *Scheduler[T]
- type Task
- type TaskManager
- type Walker
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNilTask = errors.New("dagRun: nil task") ErrTaskExist = errors.New("dagRun: task already exist") ErrNoTaskName = errors.New("dagRun: no task name") ErrNilFunc = errors.New("dagRun: nil func") ErrTaskNotExist = errors.New("dagRun: task not found") ErrSealed = errors.New("dagRun: dag is sealed") )
Functions ¶
func NopeWalker ¶
Types ¶
type FuncScheduler ¶
type FuncScheduler struct {
// contains filtered or unexported fields
}
FuncScheduler simple scheduler for func tasks
func NewFuncScheduler ¶
func NewFuncScheduler() *FuncScheduler
NewFuncScheduler build a func task scheduler
func (*FuncScheduler) Run ¶
func (d *FuncScheduler) Run() error
Run start all tasks and block till all of them done or meet critical err
func (*FuncScheduler) Submit ¶
func (d *FuncScheduler) Submit(name string, f func() error, deps ...string) *FuncScheduler
Submit provide func task to scheduler the param `name` is the taskID which should be unique, `deps` are the names of tasks that this task dependents, `f` defines what this task really does
func (*FuncScheduler) WithInjectorFactory ¶
func (d *FuncScheduler) WithInjectorFactory(injectFac InjectorFactory[types.Nil]) *FuncScheduler
type Graph ¶
func NewGraph ¶
func NewGraph() *Graph
Example ¶
fmt.Println(g().String())
Output: [A]-> [C,D,] [B]-> [A,E,D,] [C]-> [D,] [D]-> [E,] [E]-> []
func (*Graph) BFS ¶
Example ¶
graph := g() _ = graph.BFS(func(node Node) error { fmt.Println(node.String()) return nil })
Output: A C D E B
func (*Graph) DFS ¶
Example ¶
graph := g() // graph.AddEdge(nodes[4], nodes[0]) err := graph.DFS(func(node Node) error { fmt.Println(node.String()) return nil }) if err != nil { fmt.Println("err ", err) }
Output: A C D E B
type InjectorFactory ¶
type InjectorFactoryFunc ¶
type Registry ¶
type Registry[T Named] struct { // contains filtered or unexported fields }
func NewRegistry ¶
type Scheduler ¶
type Scheduler[T any] struct { // contains filtered or unexported fields }
Scheduler simple scheduler for typed tasks
func NewScheduler ¶
NewScheduler build a typed task scheduler
func NewWithInjectorFactory ¶
func NewWithInjectorFactory[T any](injectFac InjectorFactory[T]) *Scheduler[T]
NewWithInjectorFactory is shortcut of NewScheduler.WithInjectorFactory
func (*Scheduler[T]) CancelWithErr ¶
CancelWithErr cancel the tasks which has not been stated in the scheduler
func (*Scheduler[T]) Submit ¶
Submit provide typed task to scheduler, all task should implement interface Task
func (*Scheduler[T]) SubmitFunc ¶
func (d *Scheduler[T]) SubmitFunc(name string, f func(context.Context, T) error, deps ...string) error
SubmitFunc submit a func task to scheduler
func (*Scheduler[T]) WithInjectorFactory ¶
func (d *Scheduler[T]) WithInjectorFactory(injectFac InjectorFactory[T]) *Scheduler[T]
WithInjectorFactory add a injectorFactory, which run before/after each task.
type Task ¶
type Task[T any] interface { Name() string Dependencies() []string Execute(context.Context, T) error }
Task is the interface all your tasks should implement
type TaskManager ¶
func NewTaskManager ¶
func NewTaskManager[T DepTask]() TaskManager[T]
func (TaskManager[T]) GetAllTaskWithDepsByName ¶
func (t TaskManager[T]) GetAllTaskWithDepsByName(taskNames []string) (map[string]T, error)
GetAllTaskWithDepsByName get all Tasks with their parent dependencies by names