Documentation
¶
Overview ¶
Package engine keeps the live state of a runner (local logs + optional org polling), publishes changes to subscribers and executes actions. The daemon, the web UI and the in-process TUI all sit on top of it.
Index ¶
- Constants
- func Outcome(j JobView) string
- func RunKey(j JobView) string
- type Action
- type Backend
- type Engine
- func (e *Engine) Do(ctx context.Context, a Action) (string, error)
- func (e *Engine) Run(ctx context.Context, ready chan<- struct{}) error
- func (e *Engine) State(context.Context) (*State, error)
- func (e *Engine) Usage(context.Context) (*Usage, error)
- func (e *Engine) Watch(ctx context.Context) <-chan struct{}
- type JobUsage
- type JobView
- type Notice
- type Options
- type OrgJob
- type OrgRun
- type OrgState
- type ProcUsage
- type QueueState
- type QueuedJob
- type RepoGroup
- type RunGroup
- type State
- type Usage
- type UsagePoint
- type UsageSummary
Constants ¶
const ( ActRerunJob = "rerun-job" ActRerunFailed = "rerun-failed" ActRerunRun = "rerun-run" ActCancelRun = "cancel-run" ActRunnerStart = "runner-start" ActRunnerStop = "runner-stop" ActRunnerRestart = "runner-restart" ActRunnerAbort = "runner-abort-pending" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Action ¶
type Action struct {
Kind string `json:"kind"`
Repo string `json:"repo,omitempty"`
RunID string `json:"run_id,omitempty"`
JobID string `json:"job_id,omitempty"` // REST job id (check_run_id)
Force bool `json:"force,omitempty"` // runner stop/restart even if a job is running
}
Action is a request from a client.
type Backend ¶
type Backend interface {
State(ctx context.Context) (*State, error)
// Watch delivers a value whenever the state may have changed. The channel
// is closed when ctx ends or the backend goes away.
Watch(ctx context.Context) <-chan struct{}
Do(ctx context.Context, a Action) (string, error)
// Usage is the live CPU/memory of the runner and its running job.
Usage(ctx context.Context) (*Usage, error)
}
Backend is what UIs talk to: the in-process Engine or a remote daemon.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
func (*Engine) Do ¶
Do implements Backend. Every action is checked against the current state: only runs and jobs cothon is showing can be acted on.
func (*Engine) Run ¶
Run watches the runner until ctx is canceled. The first scan happens before Run returns its first state, so callers can call State right after Ready is closed.
type JobUsage ¶
type JobUsage struct {
JobID string `json:"job_id"`
Current ProcUsage `json:"current"`
Summary UsageSummary `json:"summary"`
History []UsagePoint `json:"history"`
}
type JobView ¶
type JobView struct {
*fleet.Job
HTMLURL string `json:"html_url"`
RunURL string `json:"run_url"`
Usage *UsageSummary `json:"usage,omitempty"` // finished jobs measured by cothon
}
JobView is a job plus derived links.
type OrgJob ¶
type OrgJob struct {
ID string `json:"id"`
Name string `json:"name"`
Status string `json:"status"`
Conclusion string `json:"conclusion,omitempty"`
RunnerName string `json:"runner_name,omitempty"`
Labels []string `json:"labels"`
HTMLURL string `json:"html_url"`
Started time.Time `json:"started,omitzero"`
// OnThisRunner: running here, or queued with labels this runner serves.
OnThisRunner bool `json:"on_this_runner"`
}
type OrgRun ¶
type OrgRun struct {
Repo string `json:"repo"`
Workflow string `json:"workflow"`
RunID string `json:"run_id"`
RunNumber int `json:"run_number"`
Attempt int `json:"run_attempt"`
Status string `json:"status"` // queued | in_progress | …
Branch string `json:"branch"`
Event string `json:"event"`
Actor string `json:"actor"`
HTMLURL string `json:"html_url"`
Created time.Time `json:"created"`
Jobs []OrgJob `json:"jobs"`
}
type OrgState ¶
type OrgState struct {
Name string `json:"name"`
Updated time.Time `json:"updated,omitzero"`
Warning string `json:"warning,omitempty"`
Runs []OrgRun `json:"runs"` // queued / in-progress runs, newest first
RateRemaining int `json:"rate_remaining"`
}
OrgState is the optional organization-wide view.
type QueueState ¶
type QueueState struct {
Jobs []QueuedJob `json:"jobs"` // oldest first: the next one to start is on top
Updated time.Time `json:"updated,omitzero"`
Warning string `json:"warning,omitempty"`
}
QueueState lists jobs waiting for a runner with this runner's labels.
type QueuedJob ¶
type QueuedJob struct {
Repo string `json:"repo"`
Workflow string `json:"workflow"`
RunID string `json:"run_id"`
RunNumber int `json:"run_number"`
JobID string `json:"job_id"`
Name string `json:"name"`
Branch string `json:"branch"`
Event string `json:"event"`
Actor string `json:"actor"`
HTMLURL string `json:"html_url"`
Queued time.Time `json:"queued"` // when the job was created
Labels []string `json:"labels"`
}
type RepoGroup ¶
type RepoGroup struct {
Repo string
Runs []RunGroup
Latest time.Time
Outcome string
OK, Failed, Canceled, Running int
}
RepoGroup is a repository with its runs, newest first.
func GroupRepos ¶
GroupRepos nests runs under their repo; repos ordered by latest activity.
type RunGroup ¶
type RunGroup struct {
Key string
Repo, Workflow, RunID, RunNumber, Attempt string
Ref, Event, Actor, RunURL string
Jobs []JobView // execution order
Started, Finished time.Time
Outcome string // worst outcome: running > failed > abandoned > canceled > succeeded
OK, Failed, Canceled, Running int
}
RunGroup is one workflow run attempt and the jobs this runner executed for it.
type State ¶
type State struct {
Version uint64 `json:"version"`
Updated time.Time `json:"updated"`
Runner *fleet.RunnerConfig `json:"runner,omitempty"`
RunnerDir string `json:"runner_dir"`
Listener fleet.ListenerState `json:"listener"`
Processes fleet.Processes `json:"processes"`
// Pending is a deferred runner operation waiting for the current job to
// finish: "", "stop" or "restart".
Pending string `json:"pending,omitempty"`
Jobs []JobView `json:"jobs"` // newest first
Org *OrgState `json:"org,omitempty"`
Queue *QueueState `json:"queue,omitempty"` // jobs waiting for this runner (nil: queue polling off)
Warnings []string `json:"warnings,omitempty"`
Notice *Notice `json:"notice,omitempty"` // result of the last action
}
State is an immutable snapshot published to clients. Version increases whenever anything visible changes.
func (*State) RunnerStatus ¶
RunnerStatus summarizes the runner for headers and icons.
func (*State) RunningJob ¶
RunningJob returns the job currently executing, if any.
type Usage ¶
type Usage struct {
Runner ProcUsage `json:"runner"` // listener + run.sh themselves, without jobs
Job *JobUsage `json:"job,omitempty"` // the running job's process tree
Cores int `json:"cores"`
At time.Time `json:"at"`
}
Usage is the live view.
type UsagePoint ¶
type UsageSummary ¶
type UsageSummary struct {
PeakRSS uint64 `json:"peak_rss"`
PeakCPU float64 `json:"peak_cpu"`
AvgCPU float64 `json:"avg_cpu"` // percent of one core over the sampled time
CPUSeconds float64 `json:"cpu_seconds"` // total CPU time
Samples int `json:"samples"`
}
UsageSummary is what a job used overall.