executor

package
v0.1.24 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 25 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 executor defines job execution contracts and scheduler adapters.

It owns the boundary for local process execution, scheduler submission, scheduler status resolution, cancellation, suspension, and wrapper scripts. It should execute or control jobs according to caller-provided specs without deciding queue selection, dependency scheduling, retry policy, or run finalization.

Index

Constants

View Source
const TimeoutExitCode = model.TimeoutExitCode

TimeoutExitCode is the exit code recorded for a job stopped by its timeout, matching GNU timeout.

Variables

View Source
var ErrJobNotRunning = errors.New("job is not running")

ErrJobNotRunning reports a job directory that no executor owns.

View Source
var RunSettingNames = []string{"ssh", "slurm", "pbs", "lsf", "sge"}

RunSettingNames lists the executors that take per-run settings, such as --slurm-concurrency.

View Source
var SSHCommandPath = "/usr/bin/ssh"

SSHCommandPath is the ssh binary invoked to run remote jobs; overridable (e.g. in tests, or validateExecutorCommand's availability check) since it is not always at a fixed path.

Functions

func CancelJob

func CancelJob(jobDir string, canceller Canceller) error

CancelJob cancels the submitted job in jobDir through canceller after recording the cancel, since a scheduler may keep no result for a job deleted while queued.

func ExpandShellOptions

func ExpandShellOptions(options []string) ([]string, error)

ExpandShellOptions splits shell-quoted option strings (e.g. "-p short --cpus-per-task=2") into individual CLI arguments. Shared by any executor that accepts free-form option strings, and by cmd/rotari's queue validation, which checks option quoting before a run starts.

func LSFExplicitEnvironmentVariable

func LSFExplicitEnvironmentVariable(name string) bool

LSFExplicitEnvironmentVariable reports variables omitted by LSF's documented `-env all` transfer rules. The run environment adapter adds caller values for these names to the job wrapper as a targeted correction.

func LoadSchedulerStatus

func LoadSchedulerStatus(store state.Store, jobDir string) string

func LocalHostMismatch

func LocalHostMismatch(store state.Store, executor JobExecutor, runDir string) (recordedHost string, mismatch bool)

LocalHostMismatch reports the run's recorded hostname when executor is the local executor and this process runs on a different host. The local executor signals jobs by PID, which is only meaningful on the host that spawned the process; over a shared base directory, a failed PID check on the wrong host would misleadingly report "job is not running", so callers should surface this instead before trying.

func LocalProcessGroupAlive

func LocalProcessGroupAlive(jobDir string) (alive, known bool)

LocalProcessGroupAlive reports whether the process group recorded by a local attempt exists. known is false when the PID record cannot be inspected.

func MergeEnvironment

func MergeEnvironment(base, overrides []string) []string

func RecordCancellation

func RecordCancellation(jobDir string) error

RecordCancellation writes the marker that a job's wrapper and its final result read as an explicit cancel.

func RecordCancelledJob

func RecordCancelledJob(jobDir string, job model.JobSpec, store state.Store) model.JobResult

func RejectArraySchedulerOptions

func RejectArraySchedulerOptions(options []string, names ...string) error

RejectArraySchedulerOptions rejects executor options that would conflict with the array-index flags rotari itself supplies (e.g. Slurm's --array), used both by array submission and by cmd/rotari's queue validation.

func RunLocalJob

func RunLocalJob(runDir string, job model.JobSpec, store state.Store, logf func(string, ...any)) model.JobResult

func RunLogForward

func RunLogForward(args []string) int

RunLogForward is an internal command used by wrappers only when a job has external --output or --error destinations. It runs the requested command, streaming each fd to the wrapper (for rotari's live attempt log) and to the configured destinations without requiring a tee executable on the host.

func SSHTarget

func SSHTarget(options []string) (string, []string, error)

SSHTarget parses the SSH executor's options into a target host and the remaining ssh(1) options, shared by both job submission and cmd/rotari's up-front queue validation.

func SchedulerCommandHint

func SchedulerCommandHint(binary string, output []byte, err error) error

SchedulerCommandHint clarifies two common causes of an opaque scheduler control command failure: the scheduler's client tools (scontrol/qsig/ bstop/...) not being installed on this host -- e.g. a web/CLI host outside the cluster that only shares the state directory over NFS, where the raw "executable file not found in $PATH" is easy to mistake for the job itself not running -- and the command running fine but being rejected by the scheduler itself (e.g. suspending a job that is still queued/pending rather than actually running), where Go's generic "exit status 1" hides the scheduler's own explanation unless the command's output is folded in.

func SchedulerStateExitCode

func SchedulerStateExitCode(value string) (int, bool)

func SchedulerStateTerminal

func SchedulerStateTerminal(value string) bool

func ShellQuote

func ShellQuote(value string) string

func StatusWrapperScript

func StatusWrapperScript(command []string, jobDir string, environment []string, workingDirectory, timeout string, envMode ...string) string

StatusWrapperScript runs a job's command and records its progress in status.json. A positive timeout (a model.ParseTimeout duration) stops the command that long after it starts.

func StatusWrapperScriptWithDestinations

func StatusWrapperScriptWithDestinations(command []string, jobDir string, environment []string, workingDirectory, timeout, logMode, openMode string, outputPaths, errorPaths []string, envMode ...string) string

func StatusWrapperScriptWithLogForwarder

func StatusWrapperScriptWithLogForwarder(command []string, jobDir string, environment []string, workingDirectory, timeout, openMode string, outputPaths, errorPaths []string, helper string, envMode ...string) string

func TimeoutMessage

func TimeoutMessage(seconds int) string

TimeoutMessage describes a job stopped by a timeout of seconds.

func WriteSchedulerStatus

func WriteSchedulerStatus(store state.Store, jobDir, value string, now time.Time)

Types

type ArraySubmitter

type ArraySubmitter interface {
	SubmitArray(runDir string, jobs []model.JobSpec, options []string) ([]JobHandle, error)
}

type Canceller

type Canceller interface {
	Cancel(jobDir string) error
}

type ExecutionProber

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

ExecutionProber is a bounded, read-only batch. It caches only SGE's whole queue listing, never the verdict for a particular attempt.

func NewExecutionProber

func NewExecutionProber(store state.Store, ctx context.Context) *ExecutionProber

func (*ExecutionProber) Assess

func (probe *ExecutionProber) Assess(dir, backend string) model.RecoveryExecution

Assess never treats an outcome file as proof of termination. Missing launch identities (including the acceptance/publication crash window) stay unknown.

type JobExecutor

type JobExecutor interface {
	Name() string
	// Submit returns once the job's executor owns it (Registry.Owner finds
	// it), so a cancel can reach it from then on.
	Submit(runDir string, job model.JobSpec, options []string) (JobHandle, error)
	Wait(runDir string, handle JobHandle) model.JobResult
}

type JobHandle

type JobHandle struct {
	Job    model.JobSpec
	Native string
	// contains filtered or unexported fields
}

type LSF

type LSF struct {
	Store              state.Store
	Logf               func(string, ...any)
	SubmissionRetry    schedulerSubmissionRetryPolicy
	SubmissionSpacing  *schedulerSubmissionGate
	SubmissionInterval time.Duration
}

LSF submits jobs to IBM LSF via bsub and tracks them with bjobs/bhist.

func NewLSF

func NewLSF(store state.Store, logf func(string, ...any)) LSF

func (LSF) Cancel

func (lsf LSF) Cancel(jobDir string) error

func (LSF) Name

func (LSF) Name() string

func (LSF) Resume

func (lsf LSF) Resume(jobDir string) error

func (LSF) Submit

func (lsf LSF) Submit(runDir string, job model.JobSpec, options []string) (JobHandle, error)

func (LSF) SubmitArray

func (lsf LSF) SubmitArray(runDir string, jobs []model.JobSpec, options []string) ([]JobHandle, error)

func (LSF) Suspend

func (lsf LSF) Suspend(jobDir string) error

func (LSF) Wait

func (lsf LSF) Wait(runDir string, handle JobHandle) model.JobResult

func (LSF) WithRunSettings

func (lsf LSF) WithRunSettings(settings RunSettings) JobExecutor

type Local

type Local struct {
	Store state.Store
	Logf  func(string, ...any)
}

func NewLocal

func NewLocal(store state.Store, logf func(string, ...any)) Local

func (Local) Cancel

func (local Local) Cancel(jobDir string) error

Cancel records the request before signalling. A SIGTERM that reaches the wrapper between installing its traps and spawning the command can be deferred until that command finishes, so the wrapper also reads this marker around the command launch and stops there.

A job can end between the moment a caller selects it and the signal, so a process group that is already gone is not an error: the recorded cancellation is all that is left to do.

func (Local) Name

func (Local) Name() string

func (Local) Resume

func (local Local) Resume(jobDir string) error

func (Local) Submit

func (local Local) Submit(runDir string, job model.JobSpec, options []string) (JobHandle, error)

Submit starts the job, which can be cancelled once Submit returns.

func (Local) Suspend

func (local Local) Suspend(jobDir string) error

func (Local) Wait

func (local Local) Wait(runDir string, handle JobHandle) model.JobResult

Wait waits for the job that Submit started.

type PBS

type PBS struct {
	Store              state.Store
	Logf               func(string, ...any)
	SubmissionRetry    schedulerSubmissionRetryPolicy
	SubmissionSpacing  *schedulerSubmissionGate
	SubmissionInterval time.Duration
}

PBS submits jobs to a PBS/Torque scheduler via qsub and tracks them through qstat, mirroring the Slurm executor's submit/poll/accounting model.

func NewPBS

func NewPBS(store state.Store, logf func(string, ...any)) PBS

func (PBS) Cancel

func (pbs PBS) Cancel(jobDir string) error

func (PBS) Name

func (PBS) Name() string

func (PBS) Resume

func (pbs PBS) Resume(jobDir string) error

func (PBS) Submit

func (pbs PBS) Submit(runDir string, job model.JobSpec, options []string) (JobHandle, error)

func (PBS) SubmitArray

func (pbs PBS) SubmitArray(runDir string, jobs []model.JobSpec, options []string) ([]JobHandle, error)

func (PBS) Suspend

func (pbs PBS) Suspend(jobDir string) error

func (PBS) Wait

func (pbs PBS) Wait(runDir string, handle JobHandle) model.JobResult

func (PBS) WithRunSettings

func (pbs PBS) WithRunSettings(settings RunSettings) JobExecutor

type Registry

type Registry map[string]JobExecutor

Registry maps executor names to executors.

func NewRegistry

func NewRegistry(store state.Store, logf func(string, ...any)) Registry

NewRegistry returns the built-in executors. logf receives job submission and completion lines.

func (Registry) Known

func (registry Registry) Known(name string) bool

Known reports whether name is a registered executor.

func (Registry) Lookup

func (registry Registry) Lookup(name string) (JobExecutor, bool)

Lookup returns the executor registered under name.

func (Registry) Names

func (registry Registry) Names() []string

Names returns the registered executor names, sorted for stable output.

func (Registry) Owner

func (registry Registry) Owner(store state.Store, jobDir string) (JobExecutor, error)

Owner determines which executor owns the job recorded in jobDir, based on the metadata each executor writes on submission. Every scheduler-style executor writes job.json with its own "executor" name, so job.json alone (not its mere existence) names the owner. New local jobs do too; legacy local jobs have a pid file.

type RunSettings

type RunSettings struct {
	Concurrency      int           `json:"concurrency,omitempty"`
	Options          []string      `json:"options,omitempty"`
	SubmitInterval   time.Duration `json:"submit_interval,omitempty"`
	SubmitRetryLimit int           `json:"submit_retry_limit,omitempty"`
}

type RunSettingsConfigurer

type RunSettingsConfigurer interface {
	WithRunSettings(RunSettings) JobExecutor
}

RunSettingsConfigurer returns an executor copy configured for one run. Implementations must not mutate a shared registry instance.

type RunSettingsMap

type RunSettingsMap map[string]RunSettings

RunSettingsMap holds per-run settings by executor name.

func (RunSettingsMap) Concurrency

func (settings RunSettingsMap) Concurrency(name string, fallback int) int

Concurrency returns the concurrency set for name, or fallback when none is.

func (RunSettingsMap) Options

func (settings RunSettingsMap) Options(name string, fallback []string) []string

Options returns the options set for name, or fallback when none are.

type SGE

type SGE struct {
	Store              state.Store
	Logf               func(string, ...any)
	SubmissionRetry    schedulerSubmissionRetryPolicy
	SubmissionSpacing  *schedulerSubmissionGate
	SubmissionInterval time.Duration
}

SGE submits jobs through the common Grid Engine qsub/qstat/qacct commands. Array tasks are submitted independently so this does not depend on the differing native array support and job-id syntax across Grid Engine forks.

func NewSGE

func NewSGE(store state.Store, logf func(string, ...any)) SGE

func (SGE) Cancel

func (sge SGE) Cancel(jobDir string) error

func (SGE) Name

func (SGE) Name() string

func (SGE) Resume

func (sge SGE) Resume(jobDir string) error

func (SGE) Submit

func (sge SGE) Submit(runDir string, job model.JobSpec, options []string) (JobHandle, error)

func (SGE) Suspend

func (sge SGE) Suspend(jobDir string) error

func (SGE) Wait

func (sge SGE) Wait(runDir string, handle JobHandle) model.JobResult

func (SGE) WithRunSettings

func (sge SGE) WithRunSettings(settings RunSettings) JobExecutor

type SSH

type SSH struct {
	Store state.Store
}

SSH runs jobs on a remote host over ssh, tracking the local ssh client process for the job's lifetime.

func NewSSH

func NewSSH(store state.Store) SSH

func (SSH) Cancel

func (ssh SSH) Cancel(jobDir string) error

func (SSH) Name

func (SSH) Name() string

func (SSH) Submit

func (ssh SSH) Submit(runDir string, job model.JobSpec, options []string) (JobHandle, error)

func (SSH) Wait

func (ssh SSH) Wait(runDir string, handle JobHandle) model.JobResult

type SchedulerEvent

type SchedulerEvent struct {
	At       string `json:"at"`
	Query    string `json:"query"`
	State    string `json:"state,omitempty"`
	Error    string `json:"error,omitempty"`
	ExitCode *int   `json:"exit_code,omitempty"`
}

SchedulerEvent is one line of a job's scheduler_events.jsonl. Query is "queue", "accounting", or "result"; a queue or accounting event is written only when its outcome changes.

type SchedulerProbe

type SchedulerProbe struct {
	Command []string `json:"command"`
	Output  string   `json:"output"`
	Error   string   `json:"error,omitempty"`
}

SchedulerProbe is the output of one read-only scheduler query.

func ProbeSchedulerJob

func ProbeSchedulerJob(store state.Store, attemptDir string) []SchedulerProbe

ProbeSchedulerJob runs the queue and accounting queries rotari polls with for the scheduler job recorded in attemptDir's job.json, and returns their raw output. A job without a scheduler job ID has none.

type SchedulerStatus

type SchedulerStatus struct {
	State     string `json:"state"`
	UpdatedAt string `json:"updated_at"`
}

type Slurm

type Slurm struct {
	Store              state.Store
	Logf               func(string, ...any)
	SubmissionRetry    schedulerSubmissionRetryPolicy
	SubmissionSpacing  *schedulerSubmissionGate
	SubmissionInterval time.Duration
}

Slurm submits jobs to Slurm via sbatch and tracks them through squeue/sacct. See submitSlurmJob and waitSlurmJob for the details.

func NewSlurm

func NewSlurm(store state.Store, logf func(string, ...any)) Slurm

func (Slurm) Cancel

func (slurm Slurm) Cancel(jobDir string) error

func (Slurm) Name

func (Slurm) Name() string

func (Slurm) Resume

func (slurm Slurm) Resume(jobDir string) error

func (Slurm) Submit

func (slurm Slurm) Submit(runDir string, job model.JobSpec, options []string) (JobHandle, error)

func (Slurm) SubmitArray

func (slurm Slurm) SubmitArray(runDir string, jobs []model.JobSpec, options []string) ([]JobHandle, error)

func (Slurm) SupportsSparseArray

func (Slurm) SupportsSparseArray() bool

func (Slurm) Suspend

func (slurm Slurm) Suspend(jobDir string) error

func (Slurm) Wait

func (slurm Slurm) Wait(runDir string, handle JobHandle) model.JobResult

func (Slurm) WithRunSettings

func (slurm Slurm) WithRunSettings(settings RunSettings) JobExecutor

type SparseArraySupporter

type SparseArraySupporter interface {
	SupportsSparseArray() bool
}

type Suspender

type Suspender interface {
	Suspend(jobDir string) error
	Resume(jobDir string) error
}

type WrapperStatus

type WrapperStatus struct {
	Phase      string   `json:"phase"`
	ExitCode   int      `json:"exit_code,omitempty"`
	Error      string   `json:"error,omitempty"`
	Hosts      []string `json:"hosts,omitempty"`
	StartedAt  string   `json:"started_at,omitempty"`
	FinishedAt string   `json:"finished_at,omitempty"`
}

WrapperStatus is the contents of status.json, written by StatusWrapperScript as a job runs and read back by both the local and scheduler executors (and by cmd/rotari's show/web/run-summary code, which polls it directly).

func LoadWrapperStatus

func LoadWrapperStatus(store state.Store, path string) (WrapperStatus, bool)

Jump to

Keyboard shortcuts

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