Documentation
¶
Overview ¶
Package scriptalert routes the alert a failed scheduled run raises to the people, personas and notification channels an operator names (#1724, #2909).
The alert always reaches the script's owner: they are accountable for the automation and can fix it. What this adds is everyone else who should know, configured once for every script in the platform_settings section this package owns, so a team watching a chat channel or its Inbox sees a nightly automation fail without each owner forwarding it.
Index ¶
Constants ¶
const SettingsSection = "script_run_alert"
SettingsSection is the platform_settings section holding the configuration. It is a stored key: renaming it would strand every deployment's channels behind a section nothing reads.
Variables ¶
var ErrNotFound = errors.New("scriptalert: settings not found")
ErrNotFound is returned by the store when the alert has never been configured. Callers apply the zero Settings, which posts nowhere.
Functions ¶
This section is empty.
Types ¶
type Poster ¶
type Poster struct {
// contains filtered or unexported fields
}
Poster sends a failed run's alert to the configured recipients.
func NewPoster ¶
func NewPoster(settings SettingsStore, sender *notifyalert.Sender) *Poster
NewPoster builds the poster, or nil when either dependency is absent.
func (*Poster) Post ¶
func (p *Poster) Post(ctx context.Context, key string, payload notification.Payload, told []string) (int, error)
Post tells the configured people and persona members, leaving out those in told (the owner, told already), posts to the configured channels under key, and returns how many people and channels it was queued for. A failure to read the settings is returned for the caller to log; it sends nowhere and fails nothing else.
type Settings ¶
type Settings struct {
// Recipients is who the alert is sent to (#2909): people, each member
// of a persona, and channels.
Recipients notification.Routing `json:"recipients"`
// UpdatedBy and UpdatedAt describe the last admin write. They live in the
// platform_settings audit columns, so they are excluded from the value.
UpdatedBy string `json:"-"`
UpdatedAt time.Time `json:"-"`
}
Settings is the operator's configuration: who is told of a failed scheduled run besides its owner.
func SettingsOf ¶
func SettingsOf(ctx context.Context, store SettingsStore) (Settings, error)
SettingsOf returns the stored configuration, or the zero Settings when none has been written.
func (Settings) View ¶
func (s Settings) View() SettingsView
View maps stored settings to the read shape, with [] for an empty list.
type SettingsInput ¶
type SettingsInput struct {
Recipients *notification.RoutingInput `json:"recipients,omitempty"`
}
SettingsInput is the write shape. A list left out keeps the stored one; an empty list clears it.
func (*SettingsInput) Settings ¶
func (in *SettingsInput) Settings(stored notification.Routing) (Settings, error)
Settings maps the input over the stored recipients to the settings to store, or the reason its recipients are invalid. Whether each persona and channel exists is checked by the admin route, which holds them.
type SettingsStore ¶
type SettingsStore interface {
// Get returns the stored configuration, or ErrNotFound.
Get(ctx context.Context) (*Settings, error)
// Set upserts the configuration.
Set(ctx context.Context, s Settings, author string) error
}
SettingsStore persists the configuration.
func NewPostgresStore ¶
func NewPostgresStore(db *sql.DB) SettingsStore
NewPostgresStore creates the store over db.
type SettingsView ¶
type SettingsView struct {
Recipients notification.Routing `json:"recipients"`
UpdatedBy string `json:"updated_by,omitempty" example:"admin@example.com"`
UpdatedAt time.Time `json:"updated_at"`
}
SettingsView is the read shape.