Documentation ¶
Index ¶
- Constants
- Variables
- func IsTaskSource(task *Task, path string) (matches bool)
- func Logf(ctx context.Context, f string, args ...interface{})
- func Run(options ...RunOption)
- type DependencyChange
- type Executor
- func (e *Executor) Config() *config.Config
- func (e *Executor) Invalidate(task *Task, event InvalidationEvent)
- func (e *Executor) Run(ctx context.Context, taskNames []string, runtime *Runtime) error
- func (e *Executor) ShellRun(ctx context.Context, command string, opts ...shell.RunOption) error
- func (e *Executor) Subscribe() (events <-chan ExecutorEvent)
- func (e *Executor) Tasks() []*TaskHandler
- type ExecutorEvent
- type ExecutorEventKind
- type ExecutorOption
- type ExecutorSetupEvent
- type FileChange
- type FlagArg
- type InvalidationEvent
- type InvalidationReason
- type KeepAliveStopped
- type LogProvider
- type Logger
- type Registry
- type RunOption
- type RunnerLogger
- type Runtime
- type Task
- type TaskCompletedEvent
- type TaskDiagnosticEvent
- type TaskFailedEvent
- type TaskFlag
- type TaskHandler
- type TaskHandlerExecutionState
- type TaskInvalidatedEvent
- type TaskLogEvent
- type TaskLogEventStream
- type TaskOption
- type TaskStartedEvent
- type TaskStoppedEvent
- type UserRestart
- type WatcherEnhancer
Constants ¶
const ( ExecutorEventKind_TaskStarted ExecutorEventKind = "task.started" ExecutorEventKind_TaskCompleted = "task.completed" ExecutorEventKind_TaskFailed = "task.failed" ExecutorEventKind_TaskStopped = "task.stopped" ExecutorEventKind_TaskInvalidated = "task.invalidated" ExecutorEventKind_TaskDiagnostic = "task.diagnostic" ExecutorEventKind_TaskLog = "task.log" ExecutorEventKind_ExecutorSetup = "executor.setup" )
const ( StringTypeFlag string = "string" BoolTypeFlag string = "bool" IntTypeFlag string = "int" Float64TypeFlag string = "float64" DurationTypeFlag string = "duration" )
const ( TaskHandlerExecutionState_Invalid TaskHandlerExecutionState = "invalid" TaskHandlerExecutionState_Running = "running" TaskHandlerExecutionState_Error = "error" TaskHandlerExecutionState_Done = "done" TaskHandlerExecutionState_Canceled = "canceled" )
Variables ¶
var Add = DefaultRegistry.Add
Add registers a task, failing if the name has already been taken.
var DefaultRegistry = NewRegistry()
DefaultRegistry is where tasks are registered to through the package-level functions Add, Group and Tasks.
var Group = DefaultRegistry.Group
Group creates a pseudo-task that groups other tasks underneath it.
var TaskHandlerExecutionStateMap = map[taskExecutionState]TaskHandlerExecutionState{ // contains filtered or unexported fields }
var Tasks = DefaultRegistry.Tasks
Tasks returns all registered tasks in alphabetical order.
Functions ¶
func IsTaskSource ¶
IsTaskSource checks if a provided path matches a source glob for the task.
Types ¶
type DependencyChange ¶
type DependencyChange struct {
Source *Task
}
func (DependencyChange) Description ¶
func (f DependencyChange) Description() string
func (DependencyChange) Reason ¶
func (f DependencyChange) Reason() InvalidationReason
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
Executor constructs and executes a DAG for the tasks specified and desired. It maintains the state of execution for individual tasks, accepts invalidation events, and schedules re-executions when necessary.
func NewExecutor ¶
func NewExecutor(config *config.Config, tasks []*Task, opts ...ExecutorOption) *Executor
NewExecutor initializes a new executor.
func (*Executor) Invalidate ¶
func (e *Executor) Invalidate(task *Task, event InvalidationEvent)
Invalidate marks a task and its dependencies as invalidated. If any tasks become invalidated from this call, Invalidate() will also schedule a re-execution of the DAG.
func (*Executor) ShellRun ¶
ShellRun executes a shell.Run with some default options: Commands for tasks are automatically logged (stderr and stdout are forwarded). Commands run in a consistent environment (configurable on a taskrunner level). Commands run in taskrunner's working directory.
func (*Executor) Subscribe ¶
func (e *Executor) Subscribe() (events <-chan ExecutorEvent)
Subscribe returns a channel of executor-level events. Each invocation of Events() returns a new channel. The done function should be called to unregister this channel.
func (*Executor) Tasks ¶
func (e *Executor) Tasks() []*TaskHandler
type ExecutorEvent ¶
type ExecutorEvent interface { Timestamp() time.Time Kind() ExecutorEventKind TaskHandler() *TaskHandler }
type ExecutorEventKind ¶
type ExecutorEventKind string
type ExecutorOption ¶
type ExecutorOption func(*Executor)
func ShellRunOptions ¶
func ShellRunOptions(opts ...shell.RunOption) ExecutorOption
func WithWatchMode ¶
func WithWatchMode(watchMode bool) ExecutorOption
WithWatchMode controls the file watching mode.
func WithWatcherEnhancer ¶
func WithWatcherEnhancer(we WatcherEnhancer) ExecutorOption
WithWatcherEnhancer adds a watcher enhancer to run when creating the enhancer.
type ExecutorSetupEvent ¶
type ExecutorSetupEvent struct {
// contains filtered or unexported fields
}
func (*ExecutorSetupEvent) Kind ¶
func (e *ExecutorSetupEvent) Kind() ExecutorEventKind
func (ExecutorSetupEvent) TaskHandler ¶
func (e ExecutorSetupEvent) TaskHandler() *TaskHandler
type FileChange ¶
type FileChange struct {
File string
}
func (FileChange) Description ¶
func (f FileChange) Description() string
func (FileChange) Reason ¶
func (f FileChange) Reason() InvalidationReason
type InvalidationEvent ¶
type InvalidationEvent interface { Reason() InvalidationReason Description() string }
type InvalidationReason ¶
type InvalidationReason int
const ( InvalidationReason_Invalid InvalidationReason = iota InvalidationReason_FileChange InvalidationReason_DependencyChange InvalidationReason_KeepAliveStopped InvalidationReason_UserRestart )
type KeepAliveStopped ¶
type KeepAliveStopped struct{}
func (KeepAliveStopped) Description ¶
func (f KeepAliveStopped) Description() string
func (KeepAliveStopped) Reason ¶
func (f KeepAliveStopped) Reason() InvalidationReason
type LogProvider ¶
type Logger ¶
func LoggerFromContext ¶
LoggerFromContext gets the logger from the context.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is an object that keeps track of task definitions.
func (*Registry) Add ¶
func (r *Registry) Add(t *Task, opts ...TaskOption) *Task
Add registers a task, failing if the name has already been taken.
type RunOption ¶
type RunOption func(options *Runtime)
func ExecutorOptions ¶
func ExecutorOptions(opts ...ExecutorOption) RunOption
type RunnerLogger ¶
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
Runtime represents the external interface of an Executor's runtime. It is how taskrunner extensions can register themselves to taskrunner's lifecycle.
func (*Runtime) OnStop ¶
OnStop is before taskrunner exits (either because its tasks have exited or because of a SIGINT).
func (*Runtime) Subscribe ¶
func (r *Runtime) Subscribe(f func(events <-chan ExecutorEvent) error)
Subscribe provides an events stream channel that is populated after taskrunner has loaded. The channel is read-only and is automatically closed on exit.
type Task ¶
type Task struct { Name string // A one or two sentence description of what the task does Description string // [DEPRECATED] This fn is deprecated in favor of RunWithFlags // Run is called when the task should be run. The function should gracefully // handle context cancelation. Run func(ctx context.Context, shellRun shell.ShellRun) error // RunWithFlags is called when the task should be run // and includes all flags passed to the task. The function // should gracefully handle context cancellation. RunWithFlags func(ctx context.Context, shellRun shell.ShellRun, flagArgs map[string]FlagArg) error // Flags is a list of supported flags for this task (e.g. --var="val", -bool). // Only the flags specified in this list will be considered valid arguments to a task. Flags []TaskFlag ShouldInvalidate func(event InvalidationEvent) bool // Dependencies specifies any tasks that this task depends on. When those // dependencies are invalidated, this task will also be invalidated. Dependencies []*Task // KeepAlive specifies whether or not this task is long lived. // If true, this task will be restarted when it exits, regardless of exit code. KeepAlive bool // Hidden specifies whether or not to show the task when -list is called. Hidden bool // Sources specifies globs that this task depends on. When those files change, // the task will be invalidated. Sources []string // Ignore is a set of globs subtracted from Sources. Ignore []string // IsGroup specifies whether this task is a pseudo-task that groups // other tasks underneath it. IsGroup bool }
type TaskCompletedEvent ¶
func (*TaskCompletedEvent) Kind ¶
func (e *TaskCompletedEvent) Kind() ExecutorEventKind
func (TaskCompletedEvent) TaskHandler ¶
func (e TaskCompletedEvent) TaskHandler() *TaskHandler
type TaskDiagnosticEvent ¶
type TaskDiagnosticEvent struct { Error error // contains filtered or unexported fields }
func (*TaskDiagnosticEvent) Kind ¶
func (e *TaskDiagnosticEvent) Kind() ExecutorEventKind
func (TaskDiagnosticEvent) TaskHandler ¶
func (e TaskDiagnosticEvent) TaskHandler() *TaskHandler
type TaskFailedEvent ¶
type TaskFailedEvent struct { Error error // contains filtered or unexported fields }
func (*TaskFailedEvent) Kind ¶
func (e *TaskFailedEvent) Kind() ExecutorEventKind
func (TaskFailedEvent) TaskHandler ¶
func (e TaskFailedEvent) TaskHandler() *TaskHandler
type TaskFlag ¶
type TaskFlag struct { // Description should be a string that describes what effect passing the flag to a task has. // This description is shown automatically in the generated --help message. // This field must be non-empty. Description string // ShortName is the single character version of the flag. If not 0, the // option flag can be 'activated' using -<ShortName>. Either ShortName // or LongName needs to be non-empty. ShortName rune // LongName is the multi-character version of the flag. If not "", the flag can be // activated using --<LongName>. Either ShortName or LongName needs to be non-empty. LongName string // Default is the default value for the flag. Default string // ValueType describes what the flag type is (e.g. --flag [ValueType]) // and can be one of either: StringTypeFlag, BoolTypeFlag, // IntTypeFlag, Float64TypeFlag, or DurationTypeFlag. // Its value is shown automatically in the generated --help message. // This field must be non-empty. ValueType string }
type TaskHandler ¶
type TaskHandler struct {
// contains filtered or unexported fields
}
func NewTaskHandler ¶
func NewTaskHandler(execution *taskExecution) *TaskHandler
func (*TaskHandler) Definition ¶
func (h *TaskHandler) Definition() *Task
func (*TaskHandler) Invalidate ¶
func (h *TaskHandler) Invalidate(reason InvalidationEvent)
func (*TaskHandler) State ¶
func (h *TaskHandler) State() TaskHandlerExecutionState
type TaskHandlerExecutionState ¶
type TaskHandlerExecutionState string
type TaskInvalidatedEvent ¶
type TaskInvalidatedEvent struct { Reasons []InvalidationEvent // contains filtered or unexported fields }
func (*TaskInvalidatedEvent) Kind ¶
func (e *TaskInvalidatedEvent) Kind() ExecutorEventKind
func (TaskInvalidatedEvent) TaskHandler ¶
func (e TaskInvalidatedEvent) TaskHandler() *TaskHandler
type TaskLogEvent ¶
type TaskLogEvent struct { Message string Stream TaskLogEventStream // contains filtered or unexported fields }
func (*TaskLogEvent) Kind ¶
func (e *TaskLogEvent) Kind() ExecutorEventKind
func (TaskLogEvent) TaskHandler ¶
func (e TaskLogEvent) TaskHandler() *TaskHandler
type TaskLogEventStream ¶
type TaskLogEventStream int
const ( TaskLogEventStdout TaskLogEventStream = iota TaskLogEventStderr )
type TaskOption ¶
type TaskStartedEvent ¶
type TaskStartedEvent struct {
// contains filtered or unexported fields
}
func (*TaskStartedEvent) Kind ¶
func (e *TaskStartedEvent) Kind() ExecutorEventKind
func (TaskStartedEvent) TaskHandler ¶
func (e TaskStartedEvent) TaskHandler() *TaskHandler
type TaskStoppedEvent ¶
type TaskStoppedEvent struct {
// contains filtered or unexported fields
}
func (*TaskStoppedEvent) Kind ¶
func (e *TaskStoppedEvent) Kind() ExecutorEventKind
func (TaskStoppedEvent) TaskHandler ¶
func (e TaskStoppedEvent) TaskHandler() *TaskHandler
type UserRestart ¶
type UserRestart struct{}
func (UserRestart) Description ¶
func (f UserRestart) Description() string
func (UserRestart) Reason ¶
func (f UserRestart) Reason() InvalidationReason
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
This package provides buildkite annotations of failed tasks per buildkite job.
|
This package provides buildkite annotations of failed tasks per buildkite job. |
Package config provides configuration for taskrunner.
|
Package config provides configuration for taskrunner. |