Documentation
¶
Overview ¶
Package scriptincident holds each automation's failure incident (#2041): the failed scheduled run that opens it is the one its owner and the operator's channels are told of, the failed runs while it stays open are counted rather than sent, and the run that succeeds closes it and is told as the recovery. The rows are script_failure_incidents.
Index ¶
- Constants
- func Recipients(sc *script.Script) []string
- func RecordedResult(ctx context.Context, runs RunReader, run *script.Run, res script.RunResult) script.RunResult
- func Repeats(ctx context.Context, runs any, scriptID string) int
- func RunPage(portalURL, scriptID, runID string) string
- type Alerter
- type Incident
- type Notifier
- type Opening
- type Poster
- type RunReader
- type Store
Constants ¶
const ( // WriteTimeout bounds each alert write. It is one insert, and a run that // has already been recorded must not be held open behind a slow database // for the sake of telling somebody about it. WriteTimeout = 5 * time.Second )
Alert bounds.
Variables ¶
This section is empty.
Functions ¶
func Recipients ¶
Recipients is who hears about a failing automation: the script's owner, who is accountable for it and can fix it.
func RecordedResult ¶ added in v1.171.0
func RecordedResult(ctx context.Context, runs RunReader, run *script.Run, res script.RunResult) script.RunResult
RecordedResult is the result the run was recorded with, which is what an incident follows. A run that saved state can be recorded as failed although it finished successfully, when another run moved the state first (runstate.CauseStateConflict); the run row says so.
func Repeats ¶ added in v1.171.0
Repeats is how many runs of the script have failed in a row ending on the same error, the one just recorded included, or zero where the run store cannot say. The store that keeps runs in PostgreSQL can; a store assembled for a test need not, and its alerts read as a first failure.
Types ¶
type Alerter ¶
Alerter tells a script's owner and the operator's channels what a finished run means for the script's incident. Store nil tells every failure and no recovery; Notifier or Channels nil skips that half.
func (Alerter) Failed ¶
func (a Alerter) Failed(ctx context.Context, run *script.Run, sc *script.Script, res script.RunResult, repeats func() int)
Failed tells of a failed scheduled run when it opens the incident; one counted on an incident already open sends nothing. repeats is read only when the run is told. When the incident cannot be recorded the run is told anyway, since a repeated email is better than none.
func (Alerter) Succeeded ¶
Succeeded closes the script's incident and tells of the recovery, when one was open. Any succeeded run closes it, as any succeeded run ends the failure the session-start notice reports (#1934). It says the latest run succeeded; it does not say that what the failed runs left undone was done.
type Incident ¶
type Incident struct {
OpenedAt time.Time
OpeningRunID string
OpeningCause string
OpeningError string
FailedRuns int
LastFailedAt time.Time
}
Incident is a script's failure incident as it stood when it closed.
type Notifier ¶
type Notifier interface {
Notify(ctx context.Context, recipient, category string, p notification.Payload) (bool, error)
}
Notifier queues one notification for a person.
type Opening ¶
type Opening struct {
ScriptID string
RunID string
Cause string
// Error is the line of the run's error that names the failure: its last.
Error string
FailedAt time.Time
}
Opening is the failed run that may open a script's incident.
type Poster ¶
type Poster interface {
Post(ctx context.Context, key string, p notification.Payload) (int, error)
}
Poster posts an alert to the operator's notification channels under a key.
type Store ¶
type Store interface {
// Open records a failed run, reporting whether it opened the incident
// (true) or was counted on one already open (false).
Open(ctx context.Context, o Opening) (bool, error)
// Close ends the script's incident and returns it, or nil when none was
// open.
Close(ctx context.Context, scriptID string) (*Incident, error)
}
Store holds each script's open incident.
func NewPostgresStore ¶
NewPostgresStore creates the store over db.