Documentation ¶
Overview ¶
Package xgraph runs a sequence of user defined jobs in an appropriate order, given their dependencies.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrMissingCallback = errors.New("missing callback for BasicJob")
ErrMissingCallback indicates that a callback is missing on a BasicJob.
Functions ¶
This section is empty.
Types ¶
type BasicJob ¶
type BasicJob struct { // JobName of the BasicJob. // Required. JobName string // RunCallback is called when the BasicJob is run. // Required. RunCallback func() error // ShouldRunCallback returns whether the BasicJob should be run. // Defaults to a function that always returns true. ShouldRunCallback func() (bool, error) // Deps is a list of dependencies for the BasicJob. // Defaults to []string{}. Deps []string }
BasicJob is a simple type which implements Job.
func (BasicJob) Dependencies ¶
Dependencies returns the dependencies list of the BasicJob. Never returns an error. If Deps is nil, returns an empty slice for the dependencies.
type BuildDependencyError ¶
type BuildDependencyError []string
BuildDependencyError is an error indicating that dependencies failed
func (BuildDependencyError) Error ¶
func (bde BuildDependencyError) Error() string
type CallbackTracker ¶
type CallbackTracker func(err error)
CallbackTracker is a WorkTracker which calls a function on completion.
func (CallbackTracker) OnComplete ¶
func (ct CallbackTracker) OnComplete(err error)
OnComplete calls the callback and implements WorkTracker.
type DependencyCycleError ¶
type DependencyCycleError []string
DependencyCycleError is an error indicating that there is a dependency cycle
func (DependencyCycleError) Error ¶
func (dce DependencyCycleError) Error() string
type EventHandler ¶
type EventHandler interface { // OnQueued is called when a Job has been queued (waiting for dependencies) OnQueued(job string) // OnStart is called when a Job has been started OnStart(job string) // OnFinish is called when a Job has finished OnFinish(job string) // OnError is called when a Job fails OnError(job string, err error) }
EventHandler is an interface used to process build events
var NoOpEventHandler EventHandler = nophandler{}
NoOpEventHandler is an EventHandler which does nothing
type FailHandler ¶
type FailHandler func(error)
FailHandler is a type of function used as a callback for a Promise on failure
type FinishHandler ¶
type FinishHandler func()
FinishHandler is a type of function used as a callback for a Promise on success
type Graph ¶
type Graph struct {
// contains filtered or unexported fields
}
Graph is an execution graph
func (*Graph) AddGenerator ¶
func (g *Graph) AddGenerator(generator JobGenerator) *Graph
AddGenerator adds a JobGenerator to the Graph
type Job ¶
type Job interface { // Name returns the name of the Job. Name() string // The Run method runs the job. // Is called after the dependencies have been run successfully. // A context may be provided for cancellation purposes. Run(ctx context.Context) error // ShouldRun checks if the job should be run. // Job is marked as errored if this returns an error. // Dependents will be run even if this Job does not need to be run. ShouldRun() (bool, error) // Dependencies returns a list of dependencies for the Job. // If this returns an error, the Job is marked as errored. Dependencies() ([]string, error) }
Job is an operation in the execution graph
type JobGenerator ¶
JobGenerator is a type which generates Jobs dynamically. If a job with the given name should not be generated by this generator, a nil Job should be returned. Any errors will be propogated.
type JobNotFoundError ¶
type JobNotFoundError string
JobNotFoundError is an error type indicating that a job was not found. The underlying string is the name of the job.
func (JobNotFoundError) Error ¶
func (err JobNotFoundError) Error() string
func (JobNotFoundError) String ¶
func (err JobNotFoundError) String() string
type Promise ¶
type Promise struct {
// contains filtered or unexported fields
}
Promise is a future
func NewPromise ¶
func NewPromise(fun func(FinishHandler, FailHandler)) *Promise
NewPromise returns a *Promise using the given function
func (*Promise) Then ¶
func (p *Promise) Then(success FinishHandler, failure FailHandler)
Then registers callbacks and starts the Promise if it has not been already started. If the Promise has already completed, the success/failure handler is immediately called with the resu;t. This is like Promise.then in JavaScript.
type Runner ¶
type Runner struct { Graph *Graph WorkRunner WorkRunner EventHandler EventHandler }
Runner is a tool to run graphs
type Task ¶
type Task func() error
Task is a task function.
func (Task) Run ¶
func (t Task) Run(tracker WorkTracker)
Run runs a task on the local goroutine, using the tracker to notify of completion.
type WorkRunner ¶
type WorkRunner interface { // Do calls a func asynchronously. DoTask(task Task, tracker WorkTracker) // WorkRunner is closable - Close should clean up all existing state. io.Closer }
WorkRunner is a type
func NewWorkPool ¶
func NewWorkPool(parallel uint16) WorkRunner
NewWorkPool returns a WorkRunner that uses a fixed pool of goroutines. parallel is the number of goroutines to use in the pool. If parallel is 0, then one goroutine will be used per CPU.
type WorkTracker ¶
type WorkTracker interface { // OnComplete is called when a task completes. // The error value from the job is passed as an argument. OnComplete(err error) }
WorkTracker is an interface used to track completion of jobs.