Documentation
¶
Overview ¶
Package drivestore keeps a drive durable: a record per drive under the storage root, and a lease per task. The lease keeps two drives, or a drive and `f10 finish`, from acting on one task at once.
Index ¶
- Constants
- func Create(root string, rec *Record) error
- func DriveKey(n int) string
- func Fingerprint(target, conflicts, red string) string
- func HolderOf(tasks []Task, id string) int
- func Key(args []string) string
- func Path(root string, n int) string
- type Answer
- type Catchup
- type Guard
- type HeldError
- type Holder
- type Lease
- type Live
- type Outcome
- type Record
- type Task
Constants ¶
const ( PhasePending = "pending" // not opened yet PhaseQueued = "queued" // held back by the drive's cap PhaseRunning = "running" // a skill in flight PhaseVerifying = "verifying" // the drive's own verify after a catchup PhaseRetrying = "retrying" // sending its action again after a failed attempt PhaseParked = "parked" // a skill waits for its base's code, or its branch on origin PhaseWaiting = "waiting" // finish waits for its base to be through, or the head's checks PhaseEnded = "ended" // its outcome is in )
The phases a drive record names a task's standing by.
const Dir = "drives"
Dir is the drives directory under a storage root.
Variables ¶
This section is empty.
Functions ¶
func Create ¶
Create writes rec as the next numbered record, setting its number. The file is created exclusively, so two drives started at once get two.
func Fingerprint ¶
Fingerprint is a catchup's progress state: the target it brings in, the conflicts it meets (path and blobs) and the verify command red after it. The head is left out, since a merge moves it without progress; an attempt with the fingerprint of the one before made none.
func HolderOf ¶ added in v0.71.0
HolderOf is the index of the task in tasks that holds id, -1 for none. It is the one answer to which of a record's tasks an id means: the task itself, a bundle it rides in, or one of its -suffix attempts.
Types ¶
type Answer ¶
type Answer struct {
Task string `yaml:"task"`
Skill string `yaml:"skill,omitempty"`
Text string `yaml:"text"`
At time.Time `yaml:"at"`
}
An Answer is one taken: by which task, at which skill, when.
type Catchup ¶
type Catchup struct {
Target string `yaml:"target"` // the sha the branch was caught up to
Head string `yaml:"head"` // the branch's tip when the catchup went out
// Origin is origin's copy of the branch then, what the push after the
// catchup leases against; "" when origin lacked the branch
Origin string `yaml:"origin"`
Base string `yaml:"base"` // the target's name in prose
At time.Time `yaml:"at"`
// Failed is a catchup that did not end clean; the watcher sends another
// only once the fingerprint moves
Failed bool `yaml:"failed,omitempty"`
// Fingerprint is the state a failed watcher catchup stopped at (see
// Fingerprint): the watcher sends another only once it moves
Fingerprint string `yaml:"fingerprint,omitempty"`
// TargetRef is the target's remote-tracking ref, "" for a target recorded
// nowhere; a push waits until the target is on it
TargetRef string `yaml:"target_ref,omitempty"`
// Spent is set once a push or a later skill made Origin stale, so it
// leases nothing; a record without it still holds its lease
Spent bool `yaml:"spent,omitempty"`
// Integrated is set once this catchup rewrote the branch itself, after
// Origin was read, so the lease stays sound on a resend
Integrated bool `yaml:"integrated,omitempty"`
}
A Catchup is what a branch looked like when a catchup went out, kept by the drive on its task and by the watcher on its stored report, so both lease the push after it and judge a repeat the same way.
type Guard ¶ added in v0.62.0
A Guard is where ship's catchup guard stopped: the pipeline entry and its place from 1.
type Holder ¶
type Holder struct {
PID int
Drive int // 0 for `f10 finish` itself
Watch bool // the daemon's watcher, finishing a task no drive owns
}
A Holder is who holds a lease, as its lock file names it.
type Lease ¶
A Lease is a held lock, released by Release or by the process ending.
func Acquire ¶
Acquire takes key's lease for drive (0 for finish) under the storage root, without waiting on a holder: a held one is a HeldError naming it.
type Live ¶
Live is a drive neither cancelled nor done, and whether its driver runs: holds the drive's lease. A stopped drive still lists its tasks.
func Active ¶
Active is every live drive under root, newest first; an unreadable drives dir lists none.
func ActiveOne ¶
ActiveOne is drive n when it is live, false when it is done, cancelled or has no record.
type Record ¶
type Record struct {
Number int `yaml:"number"`
Created time.Time `yaml:"created"`
Args []string `yaml:"args"` // the command line, --answer, --every, --parallel and --foreground dropped
Tasks []Task `yaml:"tasks"`
Flow string `yaml:"flow,omitempty"`
Agent string `yaml:"agent,omitempty"` // the run-wide --agent (or --model) as typed
Cancelled *time.Time `yaml:"cancelled,omitempty"`
Session string `yaml:"session,omitempty"` // the session that created it, "" from a plain terminal
// Parallel is the cap on tasks running a skill at once, as the drive
// took it; a rerun or a resume keeps it unless it passes --parallel
Parallel int `yaml:"parallel,omitempty"`
// PlanOnly is set for a batch started with --plan, whose dependents open
// on saved plans. A record written before the field has it in Args only.
PlanOnly bool `yaml:"plan_only,omitempty"`
// Answers are given and not yet taken, by task id, "" for the bare one
Answers map[string]string `yaml:"answers,omitempty"`
Answered []Answer `yaml:"answered,omitempty"`
}
A Record is one drive, kept at <storage root>/drives/<n>.yaml: what it was started with, the answers given, and how each task ended.
func Find ¶
Find is the newest record started with args that is neither cancelled nor done, nil for none.
func Update ¶
Update applies change to record n under its own lock and writes it back through a rename, so a cancel and the drive's own writes never lose one another. It returns the record as written.
func (*Record) Holds ¶ added in v0.71.0
Holds reports the record holding task id: as a task, as any member of a bundle, or with a -suffix.
type Task ¶
type Task struct {
ID string `yaml:"id"` // as typed, a suffix included
Agent string `yaml:"agent,omitempty"` // its own :profile as typed
After string `yaml:"after,omitempty"` // its one base as an id, typed or from its body
// Join is a join's bases, as ids: it waits for each to merge
Join []string `yaml:"join,omitempty"`
Skill string `yaml:"skill,omitempty"` // in flight, "" for none
Queued bool `yaml:"queued,omitempty"` // held back by the drive's cap; Phase says it too, for older readers
// Phase is where the task stands: one of the Phase names, "" in a record
// written before it was kept
Phase string `yaml:"phase,omitempty"`
// Opened is set once the task has a worktree and an agent. Phase cannot
// say it, because queued covers a task the cap holds before it opens.
Opened bool `yaml:"opened,omitempty"`
Outcome *Outcome `yaml:"outcome,omitempty"`
// Catchup is the catchup the drive last sent for the task, so a resumed
// drive still leases its push; the repeat count stays in the drive's memory
Catchup *Catchup `yaml:"catchup,omitempty"`
// Checks is the head sha a waiting finish holds for, its checks still
// running; "" while the phase waits on a base
Checks string `yaml:"checks,omitempty"`
// Guard is the stop ship's catchup guard left, as the drive read it, so
// a catchup's turn that rewrites the run still resumes ship there
Guard *Guard `yaml:"guard,omitempty"`
}
A Task is one task of a drive, as typed, and where it stands.