jobs

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 11 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 jobs runs a change that takes longer than a request, or reaches another machine, as a job: one at a time, under the advisory lock for as long as it runs, with its output kept line by line for a page to stream.

A job is a person's confirmed command, run exactly as the CLI runs it. It can pause to ask the person something (rotate's "pasted the key?"), and it can be cancelled, which stops it between steps - never inside one, so a cancelled job never leaves a step half done. It holds the process's one change slot (mutation.Exclusive) from start to end, so no preview, change or other job interleaves with it.

Index

Constants

View Source
const (
	Running   = "running"
	Waiting   = "waiting" // paused on a question
	Done      = "done"
	Failed    = "failed"
	Cancelled = "cancelled"
)

States a job is in.

Variables

View Source
var ErrCancelled = fmt.Errorf("cancelled: the steps before this one finished, and nothing after it ran: %w",
	mutation.ErrDeclined)

ErrCancelled is what a job's steps return once it has been cancelled. The history records the job as aborted.

Functions

This section is empty.

Types

type ErrBusy

type ErrBusy struct{ ID, Command string }

ErrBusy names the job already running.

func (ErrBusy) Error

func (e ErrBusy) Error() string

type Job

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

Job is one running or finished job.

func (*Job) Ask

func (j *Job) Ask(prompt, text string) bool

Ask pauses the job until the person answers, and reports their answer. A cancel answers no.

func (*Job) Step

func (j *Job) Step() error

Step reports ErrCancelled once the job has been cancelled; a job calls it between its steps.

func (*Job) View

func (j *Job) View() (View, <-chan struct{})

View is the job as it is now, and a channel closed at its next change.

func (*Job) Write

func (j *Job) Write(b []byte) (int, error)

Write appends output, one line at a time, so a page can stream it.

type Question

type Question struct {
	Prompt string
	Text   string
}

Question is what a paused job is asking. Text is shown as is, for copying: rotate's staged public key.

type Registry

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

Registry holds the jobs a server has started, and allows one to run at a time.

func NewRegistry

func NewRegistry() *Registry

NewRegistry is an empty registry.

func (*Registry) Answer

func (r *Registry) Answer(id string, yes bool) bool

Answer answers the question a job is waiting on. It reports false when the job is not waiting.

func (*Registry) Cancel

func (r *Registry) Cancel(id string) bool

Cancel stops a job at its next step, answering no to a question it waits on.

func (*Registry) Get

func (r *Registry) Get(id string) *Job

Get is the job with id, or nil.

func (*Registry) Running

func (r *Registry) Running() *Job

Running is the job running now, or nil.

func (*Registry) Start

func (r *Registry) Start(p paths.Paths, scope mutation.Scope, run func(j *Job) error) (*Job, error)

Start runs run as a job on p, under the lock, as one operation in the history. It refuses while another job runs, and waits briefly for a preview or change in flight. The job runs on after Start returns.

type View

type View struct {
	ID, Command, State, Err, OpID string
	Args                          []string
	Lines                         []string
	Question                      *Question
	Started                       time.Time
}

View is a job as a page shows it.

Jump to

Keyboard shortcuts

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