Documentation
¶
Overview ¶
Package mergejob keeps the detached merges of devctl pr merge --detach: one directory per merge under the user's state directory, named by the merge's handle, holding the job, the merge's log and, once it ended, its document.
Index ¶
- Constants
- func Alive(pid int) bool
- func Detach(cmd *exec.Cmd)
- func Prune(root string, now time.Time) error
- func ReadStatus(jobs Jobs, handle string, doc *StatusDocument) (agentcli.Verdict, error)
- func Root() (string, error)
- func Shell(script string) []string
- func ValidHandle(handle string) bool
- func WriteDocument(root, handle string, document []byte) error
- func WriteOnDone(root, handle string, o OnDone) error
- type Dir
- type Job
- type JobSummary
- type Jobs
- type Memory
- type OnDone
- type Status
- type StatusDocument
Constants ¶
const ( // StateRunning: the merge's process runs and has not written its // document. StateRunning = "running" // StateFinished: the merge wrote its document. StateFinished = "finished" // StateLost: the merge's process is gone without a document (killed, // the machine restarted); whether it merged is GitHub's to say. StateLost = "lost" )
The states of a job.
const ( // LogFile is the merge's stdout and stderr: its --progress lines and // the document. LogFile = "output.log" )
The files of a job's directory.
const Retention = 30 * 24 * time.Hour
Retention is how long a finished or lost job is kept; Start removes older ones.
const StatusCommand = "pr merge status"
StatusCommand is the command of a status document.
Variables ¶
This section is empty.
Functions ¶
func Detach ¶
Detach makes cmd start in a session of its own, so it outlives its caller's terminal, process group and signals.
func ReadStatus ¶ added in v8.151.0
ReadStatus fills doc with the merge of handle, or the list of every merge without one, and returns the verdict of an exit 0, or the outcome: the merge's own once it ended, running while it runs, usage for a lost merge or an unknown handle.
func Root ¶
Root is the directory the jobs live in: $XDG_STATE_HOME/devctl/merges, or ~/.local/state/devctl/merges without it.
func ValidHandle ¶
ValidHandle reports whether handle can name a job: no path separator, no leading dot.
func WriteDocument ¶
WriteDocument stores the merge's document, atomically: a reader sees it whole or not at all.
func WriteOnDone ¶
WriteOnDone stores the --on-done command's outcome.
Types ¶
type Dir ¶ added in v8.151.0
type Dir string
Dir is the job directories under a root: the detached merges of a laptop.
type Job ¶
type Job struct {
Handle string `json:"handle"`
Repository string `json:"repository"`
Number int `json:"number"`
PID int `json:"pid"`
StartedAt time.Time `json:"startedAt"`
// Dir is the job's directory; not stored.
Dir string `json:"-"`
}
Job is one detached merge.
func Create ¶
Create makes the directory of a new job for owner/repo#number started at now and returns the job; its handle is <owner>-<repo>-<number>-<UTC time>, with a suffix when a job of the same second exists.
func (Job) DocumentPath ¶
DocumentPath is the path the merge's document is written to.
type JobSummary ¶ added in v8.151.0
type JobSummary struct {
Handle string `json:"handle"`
Repository string `json:"repository"`
Number int `json:"number"`
State string `json:"state"`
StartedAt time.Time `json:"startedAt"`
ExitCode *int `json:"exitCode"`
}
JobSummary is one merge in the list.
type Jobs ¶ added in v8.151.0
type Jobs interface {
// List returns every merge, the newest first.
List() ([]Status, error)
// Load returns the merge of handle, an error for an unknown one.
Load(handle string) (Status, error)
}
Jobs is where the merges a status reads are kept.
type Memory ¶ added in v8.151.0
type Memory struct {
// contains filtered or unexported fields
}
Memory is the merges a long-running process keeps for as long as it runs: the server's, which writes nothing to disk.
type OnDone ¶
type OnDone struct {
Command string `json:"command"`
ExitCode int `json:"exitCode"`
Error string `json:"error,omitempty"`
}
OnDone is how the --on-done command of a job ended.
type Status ¶
type Status struct {
Job
State string
// Document is the merge's JSON document, set when finished.
Document json.RawMessage
// OnDone is the --on-done command's outcome, nil when none ran (yet).
OnDone *OnDone
}
Status is what a job's directory says about it.
type StatusDocument ¶ added in v8.151.0
type StatusDocument struct {
agentcli.Envelope
Handle string `json:"handle,omitempty"`
State string `json:"state,omitempty"`
Repository string `json:"repository,omitempty"`
Number int `json:"number,omitempty"`
PID int `json:"pid,omitempty"`
Log string `json:"log,omitempty"`
Merge json.RawMessage `json:"merge"`
OnDone *OnDone `json:"onDone"`
Jobs []JobSummary `json:"jobs,omitempty"`
}
StatusDocument is the document of devctl pr merge status.
func NewStatusDocument ¶ added in v8.151.0
func NewStatusDocument(now time.Time) StatusDocument
NewStatusDocument is the document of a status read started at now.