run

package
v0.1.18 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 10 Imported by: 0 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

Overview

Package run owns run planning and orchestration.

It uses model values and caller-provided state to decide what work should execute, what results can be carried forward, how dependencies unblock work, when retries happen, and how lanes advance a run. It does not touch project files; internal/projectrun applies these rules to a project's on-disk state, and process or scheduler details stay behind executor boundaries.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoReferenceRun = errors.New("no previous run")

ErrNoReferenceRun reports that a command without an origin needs a reference run's result, but none was given.

Functions

func ApplyCarriedOrigins

func ApplyCarriedOrigins(commands []model.QueuedCommand, origins map[string]*model.JobOrigin)

func AssignAttemptIDs

func AssignAttemptIDs(jobs []model.JobSpec, runID string, attempt int, callbacks AttemptIDCallbacks)

func BuildRunSummary

func BuildRunSummary(runID, runName, startedAt string, jobs []model.JobSpec, finalResults map[string]model.JobResult, cancelled bool, diagnose func(model.JobResult) model.JobResult) model.RunSummary

func CompleteArrayGroup

func CompleteArrayGroup(jobs []model.JobSpec, first, last int) bool

func EnvironmentEntry

func EnvironmentEntry(environment []string, name string) (string, bool)

func ExecuteJobs

func ExecuteJobs(pending []model.JobSpec, jobsByName map[string]model.JobSpec, results map[string]model.JobResult, options EngineOptions) []model.JobSpec

ExecuteJobs runs pending jobs as soon as their dependencies allow and records each result in results, which may already hold results carried from earlier runs. A failed job with retries left is started again at once, or after its retry delay; a job is never held back by unrelated jobs.

A DependsOn prerequisite must succeed; once its failure is final (no retries left) its dependents are blocked. A DependsOnFinished prerequisite only needs a final result. ExecuteJobs returns the jobs that could never become ready, for FinalizePendingResults.

func FinalizePendingResults

func FinalizePendingResults(pending []model.JobSpec, results map[string]model.JobResult)

func PrepareJobEnvironments

func PrepareJobEnvironments(jobs []model.JobSpec, config EnvironmentConfig)

func TaskOrigin

func TaskOrigin(command model.QueuedCommand, task int) *model.JobOrigin

TaskOrigin returns the origin of one task of an array command: its own task origin, or the command's origin narrowed to the task.

func WasExplicitlyCancelled

func WasExplicitlyCancelled(resultError string, cancelled func() bool, schedulerPhase func() string) bool

Types

type AttemptIDCallbacks

type AttemptIDCallbacks struct {
	MakeAttemptID func(runID, jobID string, number int) string
	AttemptJobDir func(runDir string, job model.JobSpec) (string, error)
	AttemptIDName string
	RunDirName    string
	JobDirName    string
}

type BatchLaneCallbacks

type BatchLaneCallbacks struct {
	// ValidatedJobDir resolves a job directory for scheduler submission checks.
	ValidatedJobDir func(runDir, jobID string) (string, error)
	JobCancelled    func(jobDir string) bool
	RecordCancelled func(jobDir string, job model.JobSpec) model.JobResult
	// CancelSubmitted cancels job, just submitted, through canceller when a
	// cancel reached it after the pre-start check. That cancel found the job
	// not submitted and could only record the request.
	CancelSubmitted func(job model.JobSpec, canceller executor.Canceller)
	Logf            func(string, ...any)
}

BatchLaneCallbacks lets scheduler lanes check and record cancellation of jobs that have not been submitted yet.

type DispatchOptions

type DispatchOptions struct {
	LocalConcurrency  int
	BatchMaxActive    int
	RequestedExecutor string
	ExecutorOptions   []string
	Settings          executor.RunSettingsMap
	ResolveExecutor   func(name string) (executor.JobExecutor, bool)
	Callbacks         BatchLaneCallbacks
}

DispatchOptions configures a Dispatcher.

type Dispatcher

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

Dispatcher runs jobs on one lane per executor for the whole run. Each lane starts queued jobs in the order they became ready, up to its concurrency, and a finished job frees its slot for the next queued job at once.

func NewDispatcher

func NewDispatcher(runDir string, queue model.Queue, options DispatchOptions, onStart func(model.JobSpec)) *Dispatcher

NewDispatcher returns a Dispatcher for a run. onStart, when set, is called once a job has been submitted.

func (*Dispatcher) Start

func (dispatcher *Dispatcher) Start(jobs []model.JobSpec, done func(model.JobResult))

Start runs jobs that became ready together and calls done once per job, from another goroutine, with its result. Array tasks that are ready together go to the scheduler as one native array when it supports that.

type EngineOptions

type EngineOptions struct {
	// RunRetry is the run's --retry limit for jobs without their own; -1
	// means no limit.
	RunRetry int
	// Start runs jobs that became ready together and calls done once per job,
	// from another goroutine, with its result.
	Start func(jobs []model.JobSpec, done func(model.JobResult))
	// AssignAttemptID sets the attempt ID and environment of a job's attempt,
	// numbered from 0 for each job.
	AssignAttemptID func(job *model.JobSpec, attempt int)
	// ShouldRetry reports whether a failed result may be retried at all, for
	// example false for an explicit cancellation.
	ShouldRetry func(job model.JobSpec, result model.JobResult) bool
	// Stopped reports that the run is being cancelled: no new retries start,
	// and jobs that have not started are recorded as cancelled.
	Stopped  func() bool
	Progress func(result model.JobResult, completed, total, succeeded, failed int)
	// FinalResult is called exactly once when a job reaches its final result.
	// It may enrich the result before it is stored, for example with diagnosis.
	FinalResult func(job model.JobSpec, result model.JobResult) model.JobResult
	// After runs f after d; it defaults to time.AfterFunc.
	After func(d time.Duration, f func())
}

EngineOptions configures ExecuteJobs.

type EnvironmentConfig

type EnvironmentConfig struct {
	Names             EnvironmentNames
	BaseDir           string
	ProjectName       string
	RunID             string
	RunDir            string
	RunName           string
	Bin               string
	CWD               string
	LocalConcurrency  int
	BatchConcurrency  int
	Retry             int
	ExecutorOptions   []string
	Inherited         map[string]string
	CallerEnvironment map[string]string
	JobDir            func(runDir string, job model.JobSpec) (string, error)
}

type EnvironmentNames

type EnvironmentNames struct {
	BaseDir, ProjectName, RunID, JobID, Executor, Bin, RunDir, JobDir, CWD string
	JobName, ArrayTaskID, ArrayFirst, ArrayLast, ArraySize                 string
	RunName, LocalConcurrency, BatchConcurrency, Retry, ExecutorOptions    string
}

type OriginJobs

type OriginJobs interface {
	FilterJob(origin model.JobOrigin, id string, result model.JobResult, finished bool) jobfilter.Job
}

OriginJobs optionally supplies what job filters need to know about the job an origin names: result and finished as given, with its hosts, times, and log. Without it, host, time, and diagnosis filters match no job.

type OriginResults

type OriginResults interface {
	// RunResults returns a run's summary results by job ID.
	RunResults(runID string) (map[string]model.JobResult, error)
	// AttemptResult returns the result recorded by the attempt named by
	// origin.AttemptID.
	AttemptResult(origin model.JobOrigin) (model.JobResult, bool, error)
	// Origin describes a result carried from runID for a job that has no
	// origin of its own.
	Origin(runID, jobID string, result model.JobResult) *model.JobOrigin
}

OriginResults reads the source results that queued commands' origins name. Implementations own the filesystem access and error wording for loading.

type Plan

type Plan struct {
	Execute        map[string]bool
	CarriedResults map[string]model.JobResult
	CarriedOrigins map[string]*model.JobOrigin
	// RerunDependencies names, for a job that executes only because a job it
	// depends on executes, that dependency, so a preview can say why.
	RerunDependencies map[string]string
}

Plan describes how a rerun selects work and carries finished results forward. It is deliberately independent of filesystem paths; see PlanRerun.

func PlanRerun

func PlanRerun(queue model.Queue, selection string, jobIDs []string, scope model.CommandSelector, filter jobfilter.Filter, referenceRunID string, partialArray bool, source OriginResults) (Plan, error)

PlanRerun decides which of the queue's jobs a new run executes.

Without a selection every command executes. With a selection only matching jobs execute, together with every job that depends on an executing job; a job that does not match but has a finished result carries that result forward (Origin recorded, no re-execution), and one without a result is left untouched. Each command's result comes from its origin; a command without one falls back to referenceRunID, and planning fails with ErrNoReferenceRun when that is empty. Callers resolve the reference run before the new run is recorded, so it is never the run being planned. A job's marked status replaces its result's; see model.MarkResult.

When partialArray is true, array jobs are evaluated per task, so only matching tasks execute and the rest carry their own results. When false, the whole array executes if its aggregate result matches.

A scope, when set, narrows a result selection to one stage or matrix, and filter narrows it further: jobs outside them do not execute and carry their results like non-matching jobs. jobIDs are the whole selection, and only with selection "job-id": jobs named directly are not combined with a result selection or a filter.

The plan's Execute is keyed by job ID: an array that executes as a whole is listed by its tasks, so a preview and the run read it the same way.

Jump to

Keyboard shortcuts

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