Documentation
¶
Overview ¶
Package jobs is bitc's detached-job record (spec 7).
Index ¶
- func LastExit(b []byte) (int, bool)
- func SupervisorDead(st Status) bool
- func Tail(b []byte, n int) []string
- func Terminate(log *os.File) func(code int) error
- func Wait(o WaitOptions) (string, int)
- type Record
- func (r Record) Bump() (int, error)
- func (r Record) Gen() int
- func (r Record) Lock() (func(), error)
- func (r Record) LogFor(gen int, specLog string) string
- func (r Record) ReadResult(gen int, v any) error
- func (r Record) ReadSpec(gen int) (Spec, error)
- func (r Record) ReadStatus(gen int) (Status, error)
- func (r Record) UpdateStatus(gen int, f func(*Status)) error
- func (r Record) WriteResult(gen int, v any) error
- func (r Record) WriteSpec(s Spec) error
- func (r Record) WriteStatus(s Status) error
- type Spec
- type Status
- type WaitOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LastExit ¶
LastExit returns the code of the last line that starts "__EXIT__ <int>". The log is read as text: a NUL is an ordinary byte, so "__EXIT__" after a NUL is mid-line.
func SupervisorDead ¶
SupervisorDead reports whether st's supervisor is gone: its pid is dead, reused (another start time) or a zombie (a non-reaping PID 1 keeps it as Z). No pid yet is not dead. wait, cancel and sweep (1.9) share it.
func Terminate ¶
Terminate returns a function that ends the log with "__EXIT__ <code>" on its own line. The last byte is read through the job's own fd (lastByte), so a rerun that replaced the path never confuses it.
func Wait ¶
func Wait(o WaitOptions) (string, int)
Wait polls until the job ends or the timeout passes; it returns stdout and the exit code.
Types ¶
type Record ¶
type Record struct {
Dir, WT8, Name string
// contains filtered or unexported fields
}
Record is jobs/<wt8>/<name>/.
func (Record) Bump ¶
Bump starts a new generation under the record lock, moving the old one to prev-<gen>/.
func (Record) LogFor ¶
LogFor is where generation gen's log is now: a default log (<record>/out.log) moves to prev-<gen>/ when a rerun supersedes the generation, so a reader bound to gen follows it.
func (Record) ReadResult ¶
ReadResult returns result.json of gen; os.ErrNotExist while the job runs.
func (Record) UpdateStatus ¶
UpdateStatus applies f to gen's status.json (zero if absent) under the record lock, so detach and the supervisor never drop each other's writes; a superseded gen updates its prev-<gen>/.
func (Record) WriteStatus ¶
type Spec ¶
type Spec struct {
Gen int `json:"gen"`
Name string `json:"name"`
WT8 string `json:"wt8"`
Log string `json:"log"`
Args []string `json:"args"` // run args without --detach
Cwd string `json:"cwd"`
Flags config.Flags `json:"flags"`
Result string `json:"result,omitempty"` // --result PATH
}
Spec is spec.json: what the supervisor replays. The caller's env is passed through the supervisor's process environment, never written to disk.
type Status ¶
type Status struct {
State string `json:"state"` // queued | running | ended
Gen int `json:"gen"`
Pid int `json:"pid"`
Start uint64 `json:"start"`
Log string `json:"log"`
StartedAt string `json:"started_at"`
EndedAt string `json:"ended_at,omitempty"`
}
Status is status.json.
type WaitOptions ¶
type WaitOptions struct {
Record *Record // nil with LogPath
LogPath string // --log PATH: a log with no record (legacy J8/J9)
Timeout time.Duration
Poll time.Duration // 10s, scaled by [test] time_scale
ExitJob bool // --exit job
}
WaitOptions configure a bounded wait (spec 3.2).