taskctl

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 30, 2021 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Overview

Package taskctl contains custom implementations and extensions for the github.com/taskctl/taskctl packages

Index

Examples

Constants

View Source
const JobIDVariableName = "__jobID"

Variables

This section is empty.

Functions

This section is empty.

Types

type FileOutputStore

type FileOutputStore struct {
	// contains filtered or unexported fields
}

func NewOutputStore

func NewOutputStore(path string) (*FileOutputStore, error)

func (*FileOutputStore) Reader

func (s *FileOutputStore) Reader(jobID string, taskName string, outputName string) (io.ReadCloser, error)

func (*FileOutputStore) Remove added in v0.4.0

func (s *FileOutputStore) Remove(jobID string) error

func (*FileOutputStore) Writer

func (s *FileOutputStore) Writer(jobID string, taskName string, outputName string) (io.WriteCloser, error)

type LineWriter

type LineWriter struct {
	// contains filtered or unexported fields
}

LineWriter splits written data into lines This is not used yet but prepared for streaming output later.

func (*LineWriter) Finish

func (l *LineWriter) Finish()

func (*LineWriter) Lines

func (l *LineWriter) Lines() [][]byte

func (*LineWriter) Write

func (l *LineWriter) Write(p []byte) (n int, err error)

type Opts

type Opts func(*TaskRunner)

Opts is a task runner configuration function.

func WithContexts

func WithContexts(contexts map[string]*runner.ExecutionContext) Opts

WithContexts adds provided contexts to task runner

func WithVariables

func WithVariables(variables variables.Container) Opts

WithVariables adds provided variables to task runner

type OutputStore

type OutputStore interface {
	Writer(jobID string, taskName string, outputName string) (io.WriteCloser, error)
	Reader(jobID string, taskName string, outputName string) (io.ReadCloser, error)
	Remove(jobID string) error
}

type Runner

type Runner interface {
	runner.Runner
	SetOnTaskChange(func(t *task.Task))
}

Runner extends runner.Runner (from taskctl) to implement additional features: - storage of outputs - callback on finished task (so we can f.e. schedule the next task when one is on the wait-queue) The file https://github.com/taskctl/taskctl/blob/master/pkg/runner/runner.go is the original basis of this file.

type Scheduler

type Scheduler struct {
	// contains filtered or unexported fields
}

Scheduler executes ExecutionGraph

func NewScheduler

func NewScheduler(r runner.Runner) *Scheduler

NewScheduler create new Scheduler instance

func (*Scheduler) Cancel

func (s *Scheduler) Cancel()

Cancel cancels executing tasks

func (*Scheduler) Finish

func (s *Scheduler) Finish()

Finish finishes scheduler's TaskRunner

func (*Scheduler) OnStageChange

func (s *Scheduler) OnStageChange(f func(stage *scheduler.Stage))

func (*Scheduler) Schedule

func (s *Scheduler) Schedule(g *scheduler.ExecutionGraph) error

Schedule starts execution of the given ExecutionGraph

Modified to notify on stage changes

Example
format := task.FromCommands("go fmt ./...")
build := task.FromCommands("go build ./..")
r, _ := runner.NewTaskRunner()
s := NewScheduler(r)

graph, err := scheduler.NewExecutionGraph(
	&scheduler.Stage{Name: "format", Task: format},
	&scheduler.Stage{Name: "build", Task: build, DependsOn: []string{"format"}},
)
if err != nil {
	return
}

err = s.Schedule(graph)
if err != nil {
	fmt.Println(err)
}
Output:

type TaskRunner

type TaskRunner struct {
	Stdin          io.Reader
	Stdout, Stderr io.Writer
	OutputFormat   string
	// contains filtered or unexported fields
}

TaskRunner run tasks

func NewTaskRunner

func NewTaskRunner(outputStore OutputStore, opts ...Opts) (*TaskRunner, error)

NewTaskRunner creates new TaskRunner instance

func (*TaskRunner) Cancel

func (r *TaskRunner) Cancel()

Cancel cancels execution

func (*TaskRunner) Finish

func (r *TaskRunner) Finish()

Finish makes cleanup tasks over contexts

func (*TaskRunner) Run

func (r *TaskRunner) Run(t *task.Task) error

Run run provided task. TaskRunner first compiles task into linked list of Jobs, then passes those jobs to Executor

Example
t := task.FromCommands("go fmt ./...", "go build ./..")
r, err := NewTaskRunner(nil)
if err != nil {
	return
}
err = r.Run(t)
if err != nil {
	fmt.Println(err, t.ExitCode, t.ErrorMessage())
}
fmt.Println(t.Output())
Output:

func (*TaskRunner) SetContexts

func (r *TaskRunner) SetContexts(contexts map[string]*runner.ExecutionContext) *TaskRunner

SetContexts sets task runner's contexts

func (*TaskRunner) SetOnTaskChange

func (r *TaskRunner) SetOnTaskChange(f func(t *task.Task))

SetOnTaskChange is synchronous; so you can read the task in any way inside the callback because there is no concurrent access of the task

func (*TaskRunner) SetVariables

func (r *TaskRunner) SetVariables(vars variables.Container) *TaskRunner

SetVariables sets task runner's variables

func (*TaskRunner) WithVariable

func (r *TaskRunner) WithVariable(key, value string) *TaskRunner

WithVariable adds variable to task runner's variables list. It creates new instance of variables container.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL