mergejob

package
v8.119.2 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

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

View Source
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.

View Source
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.

View Source
const Retention = 30 * 24 * time.Hour

Retention is how long a finished or lost job is kept; Start removes older ones.

Variables

This section is empty.

Functions

func Alive

func Alive(pid int) bool

Alive reports whether a process with pid runs.

func Detach

func Detach(cmd *exec.Cmd)

Detach makes cmd start in a session of its own, so it outlives its caller's terminal, process group and signals.

func Prune

func Prune(root string, now time.Time) error

Prune removes the jobs that ended before now minus Retention.

func Root

func Root() (string, error)

Root is the directory the jobs live in: $XDG_STATE_HOME/devctl/merges, or ~/.local/state/devctl/merges without it.

func Shell

func Shell(script string) []string

Shell is the command line that runs script.

func ValidHandle

func ValidHandle(handle string) bool

ValidHandle reports whether handle can name a job: no path separator, no leading dot.

func WriteDocument

func WriteDocument(root, handle string, document []byte) error

WriteDocument stores the merge's document, atomically: a reader sees it whole or not at all.

func WriteOnDone

func WriteOnDone(root, handle string, o OnDone) error

WriteOnDone stores the --on-done command's outcome.

Types

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

func Create(root, owner, repo string, number int, now time.Time) (Job, error)

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

func (j Job) DocumentPath() string

DocumentPath is the path the merge's document is written to.

func (Job) Log

func (j Job) Log() string

Log is the path of the job's log.

func (Job) Save

func (j Job) Save() error

Save writes the job's record.

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.

func List

func List(root string) ([]Status, error)

List reads every job under root, the newest first.

func Load

func Load(root, handle string) (Status, error)

Load reads the job named handle and judges its state.

func Running

func Running(root, repository string, number int) (Status, bool, error)

Running returns the running job of repository#number, if there is one.

Jump to

Keyboard shortcuts

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