scheduler

package
v1.6.5 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2024 License: GPL-3.0 Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Examples

Constants

View Source
const (
	StatusWaiting = iota
	StatusRunning
	StatusSkipped
	StatusDone
	StatusError
	StatusCanceled
)

Stage statuses

Variables

View Source
var ErrCycleDetected = errors.New("cycle detected")

ErrCycleDetected occurs when added edge causes cycle to appear

Functions

This section is empty.

Types

type ExecutionGraph

type ExecutionGraph struct {
	Env map[string][]string
	// contains filtered or unexported fields
}

ExecutionGraph is a DAG whose nodes are Stages and edges are their dependencies

func NewExecutionGraph

func NewExecutionGraph(stages ...*Stage) (*ExecutionGraph, error)

NewExecutionGraph creates new ExecutionGraph instance. It accepts zero or more stages and adds them to resulted graph

func (*ExecutionGraph) AddStage

func (g *ExecutionGraph) AddStage(stage *Stage) error

AddStage adds Stage to ExecutionGraph. If newly added stage causes a cycle to appear in the graph it return an error

func (*ExecutionGraph) Duration

func (g *ExecutionGraph) Duration() time.Duration

Duration returns execution duration

func (*ExecutionGraph) From

func (g *ExecutionGraph) From(name string) []string

From returns stages that depend on the given stage

func (*ExecutionGraph) LastError

func (g *ExecutionGraph) LastError() error

LastError returns latest error appeared during stages execution

func (*ExecutionGraph) Node

func (g *ExecutionGraph) Node(name string) (*Stage, error)

Node returns stage by its name

func (*ExecutionGraph) Nodes

func (g *ExecutionGraph) Nodes() map[string]*Stage

Nodes returns ExecutionGraph stages

func (*ExecutionGraph) To

func (g *ExecutionGraph) To(name string) []string

To returns stages on whiсh given stage depends on

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) Schedule

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

Schedule starts execution of the given ExecutionGraph

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

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

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

type Stage

type Stage struct {
	Name         string
	Condition    string
	Task         *task.Task
	Pipeline     *ExecutionGraph
	DependsOn    []string
	Dir          string
	AllowFailure bool
	Status       int32
	Env          variables.Container
	Variables    variables.Container

	Start time.Time
	End   time.Time
}

Stage is a structure that describes execution stage

func (*Stage) Duration

func (s *Stage) Duration() time.Duration

Duration returns stage's execution duration

func (*Stage) ReadStatus

func (s *Stage) ReadStatus() int32

ReadStatus is a helper to read stage's status atomically

func (*Stage) UpdateStatus

func (s *Stage) UpdateStatus(status int32)

UpdateStatus updates stage's status atomically

Jump to

Keyboard shortcuts

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