scriptincident

package
v1.146.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

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

View Source
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

func Recipients(sc *script.Script) []string

Recipients is who hears about a failing automation: the script's owner, who is accountable for it and can fix it.

func RunPage

func RunPage(portalURL, scriptID, runID string) string

RunPage is a run's page, or nothing when the deployment does not know its own public address.

Types

type Alerter

type Alerter struct {
	Store     Store
	Notifier  Notifier
	Channels  Poster
	PortalURL string
}

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

func (a Alerter) Succeeded(ctx context.Context, run *script.Run, sc *script.Script)

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

func NewPostgresStore(db *sql.DB) Store

NewPostgresStore creates the store over db.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL