Documentation
¶
Overview ¶
Package jobstatus resolves job outcomes from persisted run state.
It owns the read-side fallback chain shared by the CLI and Web projections: an attempt's own `status` file, then its wrapper `status.json` once terminal, then the persisted `scheduler_status.json`, and finally the run's recorded result: its `summary.json` result, or before the summary the carried result it recorded when it started (RecordedResults). It also resolves displayed job timestamps, including the fallback to a carried job's origin. Callers render a resolution; they should not re-implement any step of the chain or change run state.
Index ¶
- Constants
- func Artifacts(store state.Store, runsDir string, origin model.JobOrigin) (artifact.Record, bool)
- func AttemptAttributes(store state.Store, attemptDir string, now time.Time) jobfilter.Attributes
- func AttemptID(latestAttemptID string, recorded model.JobResult, hasRecorded bool) string
- func DisplayLabel(status string, accepted, carried bool) string
- func Elapsed(submitted, finished time.Time, done bool, now time.Time) time.Duration
- func FilterJob(store state.Store, runsDir string, origin model.JobOrigin, id string, ...) jobfilter.Job
- func LastOutputAt(jobDir string) (time.Time, bool)
- func ReadLog(attemptDir string) (string, error)
- func ReadStatusFile(jobDir string) (int, bool)
- func RecordedResults(run state.RunSnapshot) map[string]model.JobResult
- func ResultAttemptDir(runsDir string, origin model.JobOrigin) string
- func Timestamps(runDir, jobDir string, origin *model.JobOrigin, carried bool) (submittedAt, finishedAt string)
- func WithoutRecordedMark(label string) string
- func WrapperTerminal(status executor.WrapperStatus) bool
- type ArtifactEntry
- type ArtifactListing
- type Attempt
- type Job
- type RunTime
- type Source
Constants ¶
const ( ArtifactFile = "file" ArtifactDirectory = "directory" ArtifactOther = "other" ArtifactMissing = "missing" // ArtifactUnknown is a relative path whose base was never known. ArtifactUnknown = "unknown" )
Types an ArtifactEntry observes at its path on the viewing host.
const StatusPending = "pending"
StatusPending is the display status of a job rotari has not dispatched yet, such as one waiting for a dependency. A job queued by a scheduler is "waiting (recorded)" instead.
Variables ¶
This section is empty.
Functions ¶
func Artifacts ¶
Artifacts returns the artifact candidates recorded for the attempt that origin names under runsDir. A job carried into origin's run is read from the attempt that produced its result, as FilterJob reads it. ok is false when that attempt has no record, as in state written before discovery existed or for an attempt that never started: discovery information is unavailable, which does not mean the job had no associated files.
func AttemptAttributes ¶
AttemptAttributes reads the hosts and times an attempt directory records: the wrapper's start, or the submission when it has not started.
func AttemptID ¶ added in v0.1.21
AttemptID is the attempt a job's row shows: its latest attempt in the run, which exists from dispatch on, or without one the attempt its recorded result names, as for a carried job.
func DisplayLabel ¶
DisplayLabel is the label views show for a job: its DisplayStatus, or success (accepted) for an accepted earlier failure, marked when the result was carried from another run.
func Elapsed ¶
Elapsed is how long a job has run: from its submission to its finish, or to now while it runs. It is negative when either end is unknown (a zero time).
func FilterJob ¶
func FilterJob(store state.Store, runsDir string, origin model.JobOrigin, id string, result model.JobResult, finished bool, now time.Time) jobfilter.Job
FilterJob returns what job filters need to know about the job that origin names under runsDir: result and finished as the caller resolved them, and the hosts, times, and log of the attempt that produced them. A job carried into origin's run is read from the run it was carried from. id is the job's ID for definition conditions. Hosts recorded on result take precedence over the attempt's, and times the carry records fill in ones the attempt lacks.
func LastOutputAt ¶
LastOutputAt returns when the attempt in jobDir last wrote to its output logs, the latest modification time of its merged or separate stdout and stderr files, and false when it has written none. A running job whose last output is long past may be stuck. Logs an executor keeps on another host are not seen.
func ReadLog ¶
ReadLog returns the log of an attempt for diagnosis: its merged output, or else its stdout, or else its stderr.
func ReadStatusFile ¶
ReadStatusFile reads the attempt's plain `status` exit-code file.
func RecordedResults ¶
func RecordedResults(run state.RunSnapshot) map[string]model.JobResult
RecordedResults returns the results a run has recorded for its jobs, which the chain reads as each job's run result: its summary's once it has one, and before that the results it carries forward from earlier runs, which it records before dispatching any job. A job the run executes has no recorded result until the summary.
func ResultAttemptDir ¶
ResultAttemptDir returns the directory of the attempt that produced the result origin names: that attempt, or for a job carried into origin's run, the attempt it was carried from, as FilterJob reads it. It is "" when no such directory exists.
func Timestamps ¶
func Timestamps(runDir, jobDir string, origin *model.JobOrigin, carried bool) (submittedAt, finishedAt string)
Timestamps returns a job's submitted and finished times. A carried result uses timestamps from its origin; a job executed in this run uses only its own latest attempt's, read from jobDir as state.LatestAttempt returns it.
func WithoutRecordedMark ¶
WithoutRecordedMark drops the mark every recorded unfinished state carries, for a compact view where it tells no two states apart.
func WrapperTerminal ¶
func WrapperTerminal(status executor.WrapperStatus) bool
WrapperTerminal reports whether a wrapper `status.json` records a finished job.
Types ¶
type ArtifactEntry ¶
type ArtifactEntry struct {
Path string `json:"path"`
// DisplayPath is Path relative to the listing's working directory when
// under it, and Path otherwise.
DisplayPath string `json:"display_path"`
Basis string `json:"basis"`
Type string `json:"type"`
// Origin is a one-line account of where the candidate was found.
Origin string `json:"origin"`
Sources []artifact.Source `json:"sources"`
}
ArtifactEntry is one candidate with what the viewing host finds at its path now. A missing path may exist on another host, such as an SSH job's.
type ArtifactListing ¶
type ArtifactListing struct {
// Recorded is false when the attempt has no record: discovery
// information is unavailable, unlike a record with no candidates.
Recorded bool `json:"recorded"`
Version int `json:"version,omitempty"`
// WorkingDirectory is the directory relative references were resolved
// on, when the record names it.
WorkingDirectory string `json:"working_directory,omitempty"`
// WorkingDirectoryType is what the viewing host finds at an absolute
// WorkingDirectory now, as Type is for an entry.
WorkingDirectoryType string `json:"working_directory_type,omitempty"`
Entries []ArtifactEntry `json:"entries,omitempty"`
Diagnostics []artifact.Diagnostic `json:"diagnostics,omitempty"`
}
ArtifactListing is an attempt's artifact candidates as the CLI, JSON, and Web UI show them.
func ListArtifacts ¶
ListArtifacts returns the listing of the attempt origin names, read like Artifacts, with each path observed now. It follows symlinks and never opens a path.
type Attempt ¶
type Attempt struct {
ExitCode int
Source Source
// HasAttempt indicates an existing concrete attempt directory,
// even when it has not yet written a status file. False is not evidence
// that the job has never started.
HasAttempt bool
// Undispatched means the job's directory in an existing run directory
// is absent or holds only a cancel marker. Executors write attempt
// records before starting a job, so this is positive evidence that no
// attempt was dispatched.
Undispatched bool
// Wrapper is the attempt's `status.json`, valid when HasWrapper is set,
// whether or not its phase is terminal.
Wrapper executor.WrapperStatus
HasWrapper bool
SchedulerState string
}
Attempt is what one attempt directory records about its outcome.
func ReadAttempt ¶
ReadAttempt resolves an attempt directory's outcome: `status`, then a terminal wrapper `status.json`, then a terminal `scheduler_status.json`.
type Job ¶
type Job struct {
ExitCode int
Source Source
Attempt Attempt
Summary model.JobResult
HasSummary bool
}
Job is the resolved outcome of a job in one run: its latest attempt first, then the run's `summary.json` result.
func ReadJob ¶
ReadJob reads the job's attempt directory and resolves it against the job's summary result, if any.
func ResolveAttempt ¶
ResolveAttempt resolves a displayed attempt of a job. The run's summary result belongs to the job's latest attempt, so an older attempt resolves from its own files only and stays unfinished without a terminal state.
func ResolveJob ¶
ResolveJob applies the job-level fallback chain to an attempt already read with ReadAttempt and the job's summary result, if any.
func (Job) Accepted ¶
Accepted reports whether the run accepted the job's earlier failure as a success.
func (Job) DisplayStatus ¶
DisplayStatus classifies the latest persisted state for human/API views. Nonterminal executor states are explicitly marked as recorded, not live. A job directory missing from its run is pending; other missing or unusable records are unknown.
type RunTime ¶
type RunTime struct {
// Elapsed runs from submission to the finish, or to now while the job
// runs. It is negative when either end is unknown.
Elapsed time.Duration
// Running is true for a submitted job that has not finished.
Running bool
// Quiet is, for a running job, how long ago it last wrote output. It is
// negative when the job has written none, or is not running.
Quiet time.Duration
}
RunTime is how long a job has run and, while it runs, how long ago it last wrote output.
func MeasureRunTime ¶
MeasureRunTime measures the attempt in jobDir from its submission and finish times; a zero time is unknown. Every view of a job's run time, `show` and `jobs` alike, measures through it.
type Source ¶
type Source int
Source names the step of the fallback chain that supplied an exit code.
const ( // SourceNone means no step has a terminal outcome yet. SourceNone Source = iota // SourceStatus is the attempt's plain `status` exit-code file. SourceStatus // SourceWrapper is the attempt's wrapper `status.json` in a terminal phase. SourceWrapper // SourceScheduler is a terminal state in the attempt's // `scheduler_status.json`. SourceScheduler // SourceSummary is the job's result in the run's `summary.json`. SourceSummary )