Help us shape the future of Go! Take the 2026 Go Developer Survey

dispatch

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: PostgreSQL Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Number int
View Source
var Trace bool

Log extra debug messages

This will flood logs. Enable only when debugging the scheduler.

Functions

func Compare added in v0.20.0

func Compare(a, b Task) int

Compare tasks

Heavier tasks wins.

returns:

-1: a precedes b
 0: a equals b
+1: b precedes a

func Next added in v0.24.0

func Next() int

func TaskInit added in v1.0.0

func TaskInit(f initFunc) option

TaskInit append an init function to a plan

dispatch execute init functions on context of each task.

func Thread added in v1.0.0

func Thread(ctx context.Context) int

Thread reads worker id in context for profiling

func Wait added in v1.0.0

func Wait(id string) string

Wait for a task instead of requiring it.

Wrap a requirement with Wait to mark it as waiting req.

func WorkerInit added in v0.21.0

func WorkerInit(f initFunc) option

WorkerInit append an init function to a plan

dispatch execute init functions on context of each workers.

Types

type DotAttributer added in v1.0.0

type DotAttributer interface {
	// Attributes writes a dot attributes statements
	//
	// See https://graphviz.org/doc/info/lang.html
	Attributes(string, ...any)
}

DotAttributer describes a type that can write dot attributes statements.

Implemented by dot printer. Used by visitor to customize output.

type Header struct {
	Id       string
	Priority int
	Reqs     []string // Task dependencies.
}

Header holds task metadata

Implements Task.Describe().

func (Header) Describe

func (h Header) Describe() (string, int, []string)

func (Header) String

func (h Header) String() string

type Plan

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

Plan holds task for parallel execution

func New

func New(options ...option) *Plan

New instanciate an execution plan

func (*Plan) Add

func (p *Plan) Add(t Task)

Add registers a task

Panics if task is already registered or if a task requirement is missing.

func (*Plan) Cardinality added in v1.0.0

func (p *Plan) Cardinality() uint

func (*Plan) Checkpoint added in v0.30.0

func (p *Plan) Checkpoint(id string, reqs []string)

Checkpoint add a waiter to the plan

nil reqs creates a checkpoint on all previous tasks.

Use this to wait for a section of plan. e.g. pre-data, data, etc.

func (*Plan) Configure added in v0.21.0

func (p *Plan) Configure(options ...option)

Configure applies option to plan.

func (*Plan) Dot added in v1.0.0

func (p *Plan) Dot(w io.Writer, v dotVisiter) error

Dot write plan in dot language in a stream

The dotVisiter customizes the graph for each task.

func (*Plan) Execute

func (p *Plan) Execute(ctx context.Context, jobs uint8) error

Execute runs tasks concurrently

Executing a plan twice panics.

Returns the aggregated tasks errors. Error list includes skipped tasks.

type Task

type Task interface {
	Describe() (string, int, []string)
	Run(context.Context) error
}

Task defines a schedulable unit

Use Header to implement Describe().

type TaskAdder added in v0.26.0

type TaskAdder interface {
	Add(Task)
	Checkpoint(string, []string)
}

Jump to

Keyboard shortcuts

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