Documentation
¶
Overview ¶
Package deptask provides a tool, Runner, to run tasks in order according to its dependency.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrDup indicates task name is already used. ErrDup = errors.New("duplicated task name") // ErrCyclic indicates there're cyclic dependencies. ErrCyclic = errors.New("cyclic dependencies detected") )
Functions ¶
This section is empty.
Types ¶
type ErrMissing ¶
type ErrMissing string
ErrMissing indicates a dependency is missing.
func (ErrMissing) Error ¶
func (e ErrMissing) Error() string
type Runner ¶
type Runner interface {
// Add adds a task to Runner, will return ErrDup if name has been used.
Add(name string, taskBody task.Task, deps ...string) error
// MustAdd is like Add, but panics instead of returning error.
MustAdd(name string, taskBody task.Task, deps ...string)
// Mark some tasks to be skipped. Skipped task will not be executed, just
// pretends that it has finished successfully.
Skip(name ...string)
// CopyTo copies specified tasks and their deps to dst using dst.Add. Useful
// when testing.
//
// Non-exist tasks are ignored silently. Say you have a Runner contains four
// tasks: a, b, c (depends b) and d. Calling with a, c, f will add task a,
// b and c into dst.
//
// ErrDup returned by dst.Add is silently ignored.
//
// It will call Runner.Validate (and returns error if any) before actually
// coping tasks.
//
// State is not copied! Use with caution!
CopyTo(dst Runner, name ...string) error
// RunSync validates dependencies and runs all tasks synchronously.
//
// The order is unspecified, only dependencies are ensured.
RunSync(ctx context.Context) error
// Run validates dependencies and runs all tasks concurrently.
// You have to take care of race conditions.
Run(ctx context.Context) error
// RunSomeSync validates dependencies and runs some tasks (and deps)
// synchronously.
RunSomeSync(ctx context.Context, names ...string) error
// RunSome validates dependencies and runs some tasks (and deps)
// concurrently.
RunSome(ctx context.Context, names ...string) error
// Validate validates the Runner, reports following errors if any:
//
// - ErrMissing: one or more dependecy is missing.
// - ErrCyclic: there are cyclic dependencies.
//
// It caches the result until you call Runner.Add. Feel free to run it
// multiple times.
Validate() error
}
Runner manages task dependencies and runs the tasks.
Runner is not thread-safe, you MUST NOT share same instance amoung multiple goroutines.
Runner remembers whether a task is executed or not. Take a look at examples for detail.
Click to show internal directories.
Click to hide internal directories.