Documentation
¶
Overview ¶
Package planstore keeps the plans a task captured until an apply task takes one of them, exactly once. Each plan is a directory under <root>/.rune/plans with a record, the artifact and its summary. The state of a plan is derived from the files of that directory, so separate processes agree on it without sharing a lock.
Index ¶
- Constants
- Variables
- type ArtifactError
- type Attempt
- type AttemptInfo
- type Binding
- type Digest
- type Event
- type Git
- type Record
- type SaveInput
- type SourceError
- type State
- type Store
- func (s *Store) AttemptOf(rec Record) (AttemptInfo, bool)
- func (s *Store) Claim(rec Record, applyTask, surface string) (*Attempt, error)
- func (s *Store) Dir() string
- func (s *Store) LastAttempt(key, exceptID string) (AttemptInfo, bool)
- func (s *Store) Latest(key string) (Record, State, bool, error)
- func (s *Store) Log(e Event) error
- func (s *Store) Prune()
- func (s *Store) Save(in SaveInput) (rec Record, replaced []Record, err error)
- func (s *Store) StateOf(rec Record) State
- func (s *Store) Summary(rec Record) (string, error)
- func (s *Store) Verify(rec Record) error
- type UnusableError
Constants ¶
const ( EventPlanCreated = "plan-created" EventPlanReplaced = "plan-replaced" EventApprovalRequested = "approval-requested" EventApprovalGiven = "approval-given" EventApprovalNotGiven = "approval-not-given" EventApplyRefused = "apply-refused" EventApplyStarted = "apply-started" EventApplyFinished = "apply-finished" )
The events of the journal.
const ( MaxArtifactBytes int64 = 256 << 20 MaxSummaryBytes int64 = 1 << 20 Retention = 7 * 24 * time.Hour UnfinishedGrace = 24 * time.Hour MaxJournalBytes int64 = 1 << 20 )
The limits of the store.
Variables ¶
var ( ErrClaimed = errors.New("plan was already claimed") ErrReplaced = errors.New("plan was replaced by a newer one") ErrExpired = errors.New("plan has expired") )
Errors of Claim for a plan that is not ready.
Functions ¶
This section is empty.
Types ¶
type ArtifactError ¶
ArtifactError reports a stored file that is not what its record says. What is "artifact" or "summary".
func (*ArtifactError) Error ¶
func (e *ArtifactError) Error() string
type Attempt ¶
type Attempt struct {
ID string
Path string // the private copy of the artifact
Record Record
// contains filtered or unexported fields
}
Attempt is a claimed plan: the one run that may apply it.
func (*Attempt) Finish ¶
Finish records how the apply ended and removes the artifact, the summary and the private copy. The copy is hashed first: a copy that changed makes the attempt failed whatever the exit code. A second call returns the result of the first, because by then the copy is gone and would count as changed.
type AttemptInfo ¶
type AttemptInfo struct {
Plan string
Attempt string
ApplyTask string
Surface string
Started time.Time // from the claim, or the claim file's modification time when it cannot be read
Finished time.Time // zero when unfinished
Exit int
State State // StateApplied, StateFailed or StateUnfinished
Tampered bool
}
AttemptInfo is the one attempt to apply a plan.
type Binding ¶
type Binding struct {
WorkDir string `json:"workDir"`
Runefile string `json:"runefile"`
Config string `json:"config"`
Tool string `json:"tool,omitempty"`
ToolPath string `json:"toolPath,omitempty"`
ToolDigest string `json:"toolDigest,omitempty"`
Host string `json:"host"`
}
Binding is what a plan was made with. The engine compares it before an apply; the store only keeps it.
type Event ¶
type Event struct {
Time time.Time `json:"time"`
Event string `json:"event"`
Surface string `json:"surface"`
PlanTask string `json:"planTask"`
Plan string `json:"plan,omitempty"`
Digest string `json:"digest,omitempty"`
Args string `json:"args"`
ApplyTask string `json:"applyTask,omitempty"`
Attempt string `json:"attempt,omitempty"`
ReplacedBy string `json:"replacedBy,omitempty"`
Reason string `json:"reason,omitempty"`
Exit *int `json:"exit,omitempty"`
State string `json:"state,omitempty"`
Tampered bool `json:"tampered,omitempty"`
// Invocation is the id of the agent's call the event happened in, as
// the audit log records it (spec 052). Empty on the command line.
Invocation string `json:"invocation,omitempty"`
}
Event is one line of the journal.
type Record ¶
type Record struct {
ID string `json:"id"`
Key string `json:"key"`
Created time.Time `json:"created"`
Expires time.Time `json:"expires"`
PlanTask string `json:"planTask"`
ApplyTasks []string `json:"applyTasks"`
Args string `json:"args"`
Binding Binding `json:"binding"`
Artifact Digest `json:"artifact"`
Summary Digest `json:"summary"`
RuneVersion string `json:"runeVersion,omitempty"`
Git Git `json:"git"`
Surface string `json:"surface"`
}
Record describes one stored plan. It never holds plan or summary bytes.
type SaveInput ¶
type SaveInput struct {
Record Record
Expiry time.Duration
ArtifactPath string
SummaryPath string
MaxArtifact int64 // zero means MaxArtifactBytes
MaxSummary int64 // zero means MaxSummaryBytes
}
SaveInput is a plan to store. Record carries the fields the caller computed: Key, PlanTask, ApplyTasks, Args, Binding, RuneVersion, Git and Surface. Save fills in the rest.
type SourceError ¶
SourceError reports a file that Save cannot take.
func (*SourceError) Error ¶
func (e *SourceError) Error() string
type State ¶
type State int
State is what the files of a plan's directory say about it.
type Store ¶
type Store struct {
// Now is the clock for every time the store writes or compares. Nil means
// time.Now.
Now func() time.Time
// contains filtered or unexported fields
}
Store is the plan store of one Runefile directory.
func Open ¶
Open returns the store under root. It does not touch the file system: the store is created by the first Save.
func (*Store) AttemptOf ¶
func (s *Store) AttemptOf(rec Record) (AttemptInfo, bool)
AttemptOf returns the claim of rec and its outcome. It reports false for a record that was never claimed.
func (*Store) Claim ¶
Claim takes rec for one apply and returns a private copy of its artifact with the recorded digest. Of any number of callers one succeeds. A Claim that fails leaves the record as it was.
func (*Store) LastAttempt ¶
func (s *Store) LastAttempt(key, exceptID string) (AttemptInfo, bool)
LastAttempt returns the attempt of the newest claimed record of key, other than the record exceptID.
func (*Store) Latest ¶
Latest returns the newest record of key and its state. A store that does not exist holds no record, and is not created.
func (*Store) Log ¶
Log appends e to the journal as one line, with the clock's time when e has none. Writers take a lock file in turn, so two processes neither tear a line nor lose one while the journal is cut to its limit.
func (*Store) Prune ¶
func (s *Store) Prune()
Prune removes what the store no longer needs: the bytes of every plan that cannot be applied any more, the copies made of them, and records past their retention. It also marks the older unclaimed records of a key that a concurrent Save left unmarked. It reports nothing: a store it cannot clean now is cleaned by a later call.
func (*Store) Save ¶
Save stores the two source files as a new plan and marks every older, unclaimed plan of the same key as replaced. It returns the records it marked.
func (*Store) StateOf ¶
StateOf returns the state of a record as its files say now. A caller that looked a plan up earlier uses it to tell a plan another call has used since from one whose stored bytes went missing.
type UnusableError ¶
UnusableError reports a store directory that is a link, is not a directory or belongs to another user.
func (*UnusableError) Error ¶
func (e *UnusableError) Error() string