Types
type Batch struct {
SchemaVersion int `json:"schema_version"`
CreatedAt string `json:"created_at"`
Project string `json:"project"`
RunID string `json:"run_id"`
RunName string `json:"run_name,omitempty"`
Events []Event `json:"events"`
OmittedJobs int `json:"omitted_jobs,omitempty"`
}
func NewBatch(events []Event, settings ChannelSettings, createdAt time.Time) Batch
func (batch Batch) Empty() bool
type BrowserMessage struct {
Title string `json:"title"`
Body string `json:"body"`
// Link reports whether the message opens its run, which the "link" field
// selects.
Link bool `json:"link"`
}
BrowserMessage is one browser notification: an inbox entry and, for a page
that sees it arrive, a desktop notification.
func NewBrowserMessage(events []Event, settings ChannelSettings) (BrowserMessage, bool)
NewBrowserMessage renders one run's events with browser settings. Selected
job failures, then job successes, each up to settings.MaxJobs, and the run's
completion become sections of "field name: value" lines in settings.Fields
order. It reports false when settings select none of the events.
type ChannelSettings struct {
JobFailure bool `json:"job_failure"`
JobSuccess bool `json:"job_success"`
RunFailure bool `json:"run_failure"`
RunSuccess bool `json:"run_success"`
Fields []string `json:"fields"`
MaxJobs int `json:"max_jobs"`
}
func (settings ChannelSettings) Includes(event Event) bool
type Event struct {
Kind EventKind `json:"event"`
OccurredAt string `json:"occurred_at"`
Project string `json:"project,omitempty"`
RunID string `json:"run_id,omitempty"`
RunName string `json:"run_name,omitempty"`
RunStatus string `json:"run_status,omitempty"`
JobStatus string `json:"job_status,omitempty"`
ExitCode int `json:"exit_code,omitempty"`
Successes int `json:"success_count,omitempty"`
Failures int `json:"failure_count,omitempty"`
DiagnosisOutdated bool `json:"diagnosis_outdated,omitempty"`
Job *model.JobSpec `json:"job,omitempty"`
Result *model.JobResult `json:"result,omitempty"`
StartedAt string `json:"started_at,omitempty"`
FinishedAt string `json:"finished_at,omitempty"`
// Host and LastHeartbeatAt are where an unresponsive run's coordinator
// ran and the time its last heartbeat recorded, by that host's clock.
Host string `json:"host,omitempty"`
LastHeartbeatAt string `json:"last_heartbeat_at,omitempty"`
// SilentSeconds is how long the heartbeat had not changed when the run
// was found unresponsive, by the clock of the process that found it.
SilentSeconds int64 `json:"silent_seconds,omitempty"`
}
func NewInterruptedRunEvent(project string, run model.RunSummary, occurredAt time.Time) Event
NewInterruptedRunEvent reports run, which has its ID and, when they were
recorded, its name and start time, as interrupted.
func NewJobEvent(project, runID, runName string, job model.JobSpec, result model.JobResult, occurredAt time.Time) Event
func NewRunEvent(project string, summary model.RunSummary, occurredAt time.Time) Event
func NewUnresponsiveRunEvent(project string, run model.RunSummary, host, lastBeatAt string, silent time.Duration, occurredAt time.Time) Event
NewUnresponsiveRunEvent reports run, which has its ID and, when they were
recorded, its name and start time, as unresponsive: its coordinator on host
last wrote a heartbeat at lastBeatAt, by its own clock, and the beat had not
changed for silent.
func (event Event) Recordable() Event
Recordable returns event with only the job and result facts that the shared
field vocabulary reads, so a kept record carries no environment, executor
options, or other job settings.
func (event *Event) SetDiagnosisOutdated(outdated bool)
func (event *Event) SetTimestamps(startedAt, finishedAt string)
type EventKind string
const (
JobFinished EventKind = "job.finished"
RunFinished EventKind = "run.finished"
// RunInterrupted is a run whose process stopped before finishing it,
// found by rotari web; it is recorded for the Web inbox only.
RunInterrupted EventKind = "run.interrupted"
// RunUnresponsive is an active run whose coordinator, on another host or
// in another PID namespace, has stopped writing its heartbeat. Nothing
// proves that it stopped; it is recorded for the Web inbox only.
RunUnresponsive EventKind = "run.unresponsive"
)
type Field struct {
Name string `json:"name"`
Value any `json:"value"`
}
type Loaded struct {
Settings Settings
Path string
}
func Load(baseDir, projectName string) (Loaded, error)
Load reads the first notifications.toml of the project, the basedir, and the
global config directory. With no basedir, as for a Web terminal shell of no
project, only the global one.
type Payload struct {
SchemaVersion int `json:"schema_version"`
CreatedAt string `json:"created_at"`
Events []PayloadEvent `json:"events"`
OmittedJobs int `json:"omitted_jobs,omitempty"`
}
func NewPayload(batch Batch, selected []string, webURL, baseDir string) Payload
NewPayload builds the webhook payload for batch. webURL is the root of the
rotari web server; links open the run under baseDir's route because one
notifications.toml can serve runs of any basedir.
type PayloadEvent struct {
Event EventKind `json:"event"`
Fields []Field `json:"fields"`
}
type Settings struct {
Webhook WebhookSettings `json:"webhook"`
Browser ChannelSettings `json:"browser"`
Terminal TerminalSettings `json:"terminal"`
}
func Defaults() Settings
func Parse(data []byte) (Settings, error)
type TerminalSettings struct {
CommandFailure bool `json:"command_failure"`
CommandSuccess bool `json:"command_success"`
MinSeconds int `json:"min_seconds"`
}
TerminalSettings say which commands run in the Web terminal's shells raise
a desktop notification when they end out of sight: by how they ended and how
long they ran.
func (settings TerminalSettings) Notifies(exit *int, took time.Duration) bool
Notifies says whether a command that ended with exit (nil for none) after
took is one to notify: a failure is a status other than 0, or none.
type WebhookSettings struct {
ChannelSettings
URL string `json:"url,omitempty"`
WebURL string `json:"web_url,omitempty"`
Format string `json:"format"`
}