coordinator

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const NoTimeout = time.Duration(0)

Variables

This section is empty.

Functions

func CreateMermaidStepFlowchart

func CreateMermaidStepFlowchart(steps []*Step) string

CreateMermaidStepFlowchart creates a Mermaid flowchart from the given steps' dependencies.

func MermaidLiveChartURL

func MermaidLiveChartURL(chart string, edit bool) (string, error)

MermaidLiveChartURL returns a URL to view or edit the given Mermaid chart on mermaid.live.

The URL is based on observations about Mermaid Live Editor v11.4.0, not a published API.

Types

type Step

type Step struct {
	// Name is the name of the step. It must be unique within the release step graph.
	Name string
	// Timeout defines the deadline that should be set up for the ctx passed to Func.
	// If NoTimeout (zero), no deadline is set.
	Timeout time.Duration
	// Func is the implementation of the step. It is executed when the step is run.
	// It is run in its own goroutine and may block on network calls, retries, etc.
	// It shouldn't wait for another step to complete: this should be done using DependsOn.
	Func StepFunc
	// DependsOn is a list of steps that must all complete before Func is run.
	DependsOn []*Step
}

Step represents a step in the release. Just enough information is represented in Step to allow status to be reported, otherwise state is internal to Func.

func NewIndicatorStep

func NewIndicatorStep(name string, dependsOnAdditional ...*Step) *Step

NewIndicatorStep creates a new step with the given name and no implementation. An indicator step generally helps a release runner understand the step graph more easily by indicating what it means for a set of steps to complete, and clarify what other steps take a dependency on.

func NewRootStep

func NewRootStep(name string, timeout time.Duration, f StepFunc) *Step

NewRootStep creates a new step with the given name, implementation, and no dependencies.

func NewStep

func NewStep(name string, timeout time.Duration, f StepFunc, dependsOn ...*Step) *Step

NewStep creates a new step with the given name, implementation, and dependencies. dependsOn must contain at least one step or NewStep will panic.

If there are no dependencies, use NewRootStep instead. These funcs are separate to prevent accidentally creating a root step by omitting dependencies.

func (*Step) Then

func (s *Step) Then(name string, timeout time.Duration, f StepFunc, dependsOnAdditional ...*Step) *Step

Then creates a new step that depends on s and returns the new step. This can be used when defining a step graph to chain a sequence of steps together without as much syntactic clutter.

func (*Step) TransitiveDependencies

func (s *Step) TransitiveDependencies() ([]*Step, error)

TransitiveDependencies returns all the steps s transitively depends on. Returns an error if a cycle is detected.

The slice is topologically sorted: for each step x in the slice, every step y that x depends on precedes x. This means the topologically sorted list would be a valid order to run the steps one at a time. However, we expect to run the steps in parallel, so the execution order is not predictable in practice. The order may be useful for text representations of the graph, but in most use cases it is not relevant.

The result is reproducible for a given slice of steps and their dependency slices.

type StepFunc

type StepFunc func(ctx context.Context) error

type StepRunner

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

func (*StepRunner) Execute

func (r *StepRunner) Execute(ctx context.Context, steps []*Step) error

Execute runs a group of steps, blocking until all are complete.

If any step fails, returns the first error that occurred. If a step panics, it is recovered, wrapped as a stepPanicErr, and treated as an error.

If any step depends on a step that doesn't exist in steps, returns an error without executing.

type StepStatus

type StepStatus int
const (
	StepStatusWaiting StepStatus = iota
	StepStatusRunning
	StepStatusSucceeded
	StepStatusFailed
)

Jump to

Keyboard shortcuts

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