notify

package
v0.8.13 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: MIT Imports: 32 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	StateSchemaV1 = "dbrain.notifications.state.v1"
	StateSchemaV2 = "dbrain.notifications.state.v2"
)

Variables

View Source
var ErrStatusInvalid = errors.New("notification_status_invalid")

Functions

func NewDeliveryError

func NewDeliveryError(kind DeliveryErrorKind, code string, cause error) error

func Observe

func Observe(state State, outcome Outcome, options Options) (State, Decision, error)

func ValidateEventFacts

func ValidateEventFacts(event EventFacts) error

func ValidateNotification

func ValidateNotification(notification Notification) error

func ValidateOutcome

func ValidateOutcome(outcome Outcome) error

func ValidateState

func ValidateState(state State) error

Types

type BuzzConfig

type BuzzConfig struct {
	Enabled            bool
	RelayURL           string
	ChannelID          string
	PrivateKeyRef      string
	AllowPrivateOrigin bool
}

func LoadBuzzConfig

func LoadBuzzConfig(rootDir string) (BuzzConfig, error)

LoadBuzzConfig loads and validates the Buzz provider independently from the global notification kill switch. It is intended for read-only inspection and explicit provider tests; automatic delivery must continue to use LoadConfig.

type Config

type Config struct {
	Enabled     bool
	RepeatAfter time.Duration
	Buzz        BuzzConfig
	Slack       SlackConfig
}

func LoadConfig

func LoadConfig(rootDir string) (Config, error)

func LoadInspectionConfig

func LoadInspectionConfig(rootDir string) (Config, error)

LoadInspectionConfig loads the redacted operator view independently from the automatic-delivery kill switch. Unlike LoadConfig, it validates the repeat interval and any explicitly enabled provider even when delivery is disabled.

type CoolingIncidentStatus

type CoolingIncidentStatus struct {
	FailureType FailureType `json:"failure_type"`
	Occurrences int         `json:"occurrences"`
	RearmsAt    time.Time   `json:"rearms_at"`
}

type Decision

type Decision struct {
	Notifications []Notification
}

type DeliveryError

type DeliveryError struct {
	Kind DeliveryErrorKind
	Code string
	// contains filtered or unexported fields
}

func (*DeliveryError) Error

func (e *DeliveryError) Error() string

func (*DeliveryError) Unwrap

func (e *DeliveryError) Unwrap() error

type DeliveryErrorKind

type DeliveryErrorKind string
const (
	DeliveryErrorTemporary DeliveryErrorKind = "temporary"
	DeliveryErrorPermanent DeliveryErrorKind = "permanent"
	DeliveryErrorAmbiguous DeliveryErrorKind = "ambiguous"
)

type DeliveryRecord

type DeliveryRecord struct {
	Status        DeliveryStatus `json:"status"`
	Attempts      int            `json:"attempts"`
	LastAttemptAt time.Time      `json:"last_attempt_at,omitempty"`
	ErrorCode     string         `json:"error_code,omitempty"`
	Receipt       Receipt        `json:"receipt,omitempty"`
}

type DeliveryStatus

type DeliveryStatus string
const (
	DeliveryPending        DeliveryStatus = "pending"
	DeliveryAccepted       DeliveryStatus = "accepted"
	DeliveryPermanentError DeliveryStatus = "permanent_error"
	DeliveryAmbiguous      DeliveryStatus = "ambiguous"
	DeliveryRetired        DeliveryStatus = "retired"
)

type DeliverySummary

type DeliverySummary struct {
	NotificationID string         `json:"notification_id,omitempty"`
	Provider       string         `json:"provider,omitempty"`
	Kind           EventKind      `json:"kind,omitempty"`
	Status         DeliveryStatus `json:"status,omitempty"`
	ErrorCode      string         `json:"error_code,omitempty"`
	At             time.Time      `json:"at,omitempty"`
}

type Envelope

type Envelope struct {
	Event      EventFacts                `json:"event"`
	Deliveries map[string]DeliveryRecord `json:"deliveries"`
}

type EventFacts

type EventFacts struct {
	Kind             EventKind          `json:"kind"`
	Operation        Operation          `json:"operation"`
	Incidents        []IncidentSnapshot `json:"incidents"`
	SuppressionAfter time.Duration      `json:"suppression_after"`
	CreatedAt        time.Time          `json:"created_at"`
}

type EventKind

type EventKind string
const (
	EventFailure  EventKind = "failure"
	EventReminder EventKind = "reminder"
	EventRecovery EventKind = "recovery"
	EventTest     EventKind = "test"
)

type Factory

type Factory func(context.Context, Config) (Provider, bool, error)

type FailureDefinition

type FailureDefinition struct {
	Type      FailureType
	ErrorCode string
	Title     string
	Action    string
}

func LookupFailure

func LookupFailure(failureType FailureType) (FailureDefinition, bool)

type FailureType

type FailureType string
const (
	FailureConfigResolution     FailureType = "sync.config_resolution.failed"
	FailureMetricsOpen          FailureType = "sync.metrics.open.failed"
	FailureMetricsClose         FailureType = "sync.metrics.close.failed"
	FailureStoreOpen            FailureType = "sync.store.open.failed"
	FailureStoreClose           FailureType = "sync.store.close.failed"
	FailureOptions              FailureType = "sync.options.failed"
	FailureOutput               FailureType = "sync.output.failed"
	FailureAppleNotesPermission FailureType = "sync.apple_notes.permission_denied"
	FailureUnknown              FailureType = "sync.unknown"
)

func KnownFailureTypes

func KnownFailureTypes() []FailureType

func LookupSemanticFailure

func LookupSemanticFailure(code string) (FailureType, bool)

func LookupStageFailure

func LookupStageFailure(stage string) (FailureType, bool)

type Incident

type Incident struct {
	ID                    string        `json:"id"`
	Operation             Operation     `json:"operation"`
	FailureType           FailureType   `json:"failure_type"`
	Phase                 IncidentPhase `json:"phase"`
	FirstSeenAt           time.Time     `json:"first_seen_at"`
	LastSeenAt            time.Time     `json:"last_seen_at"`
	Occurrences           int           `json:"occurrences"`
	LastFailureEnqueuedAt time.Time     `json:"last_failure_enqueued_at"`
	NeedsRecovery         bool          `json:"needs_recovery"`
	RecoveryNotifiedAt    time.Time     `json:"recovery_notified_at,omitempty"`
}

type IncidentPhase

type IncidentPhase string
const (
	IncidentOpen    IncidentPhase = "open"
	IncidentCooling IncidentPhase = "cooling"
)

type IncidentSnapshot

type IncidentSnapshot struct {
	ID          string      `json:"id"`
	FailureType FailureType `json:"failure_type"`
	FirstSeenAt time.Time   `json:"first_seen_at"`
	LastSeenAt  time.Time   `json:"last_seen_at"`
	Occurrences int         `json:"occurrences"`
}

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func NewManager

func NewManager(options Options, store StateStore, providers []Provider, managerOptions ...ManagerOption) *Manager

func (*Manager) Observe

func (m *Manager) Observe(ctx context.Context, outcome Outcome) error

func (*Manager) Status

func (m *Manager) Status() (State, error)

func (*Manager) Test

func (m *Manager) Test(ctx context.Context, providerName string) (Receipt, error)

type ManagerOption

type ManagerOption func(*Manager)

func WithClock

func WithClock(now func() time.Time) ManagerOption

func WithDeliveryTimeout

func WithDeliveryTimeout(timeout time.Duration) ManagerOption

func WithManagerLogger

func WithManagerLogger(log func(string)) ManagerOption

func WithMetricsEmitter

func WithMetricsEmitter(emit func(metrics.Event) error) ManagerOption

type Notification

type Notification struct {
	ID               string        `json:"id"`
	IncidentIDs      []string      `json:"incident_ids"`
	Kind             EventKind     `json:"kind"`
	Operation        Operation     `json:"operation"`
	FailureTypes     []FailureType `json:"failure_types"`
	Title            string        `json:"title"`
	Body             string        `json:"body"`
	Occurrences      int           `json:"occurrences"`
	FirstSeenAt      time.Time     `json:"first_seen_at"`
	LastSeenAt       time.Time     `json:"last_seen_at"`
	CreatedAt        time.Time     `json:"created_at"`
	SuppressionAfter time.Duration `json:"suppression_after"`
}

func BuildFailureMessage

func BuildFailureMessage(incident Incident, repeatAfter time.Duration) (Notification, error)

func BuildRecoveryMessage

func BuildRecoveryMessage(incidents []Incident, createdAt time.Time, repeatAfter time.Duration) (Notification, error)

func BuildReminderMessage

func BuildReminderMessage(incident Incident, repeatAfter time.Duration) (Notification, error)

func DeriveNotification

func DeriveNotification(event EventFacts) (Notification, error)

type OpenIncidentStatus

type OpenIncidentStatus struct {
	FailureType FailureType `json:"failure_type"`
	Occurrences int         `json:"occurrences"`
	FirstSeenAt time.Time   `json:"first_seen_at"`
	LastSeenAt  time.Time   `json:"last_seen_at"`
}

type Operation

type Operation string
const OperationScheduledSyncAll Operation = "scheduled_sync_all"

type Options

type Options struct {
	RepeatAfter time.Duration
	Providers   []string
}

type Outcome

type Outcome struct {
	Operation   Operation     `json:"operation"`
	Status      OutcomeStatus `json:"status"`
	FailureType FailureType   `json:"failure_type,omitempty"`
	ErrorCode   string        `json:"error_code,omitempty"`
	StartedAt   time.Time     `json:"started_at"`
	FinishedAt  time.Time     `json:"finished_at"`
}

type OutcomeStatus

type OutcomeStatus string
const (
	OutcomeSuccess   OutcomeStatus = "success"
	OutcomeFailure   OutcomeStatus = "failure"
	OutcomeCancelled OutcomeStatus = "cancelled"
)

type Provider

type Provider interface {
	Name() string
	Deliver(context.Context, Notification) (Receipt, error)
}

type ProviderStatus

type ProviderStatus struct {
	Name           string     `json:"name"`
	Configured     bool       `json:"configured"`
	LastStatus     string     `json:"last_status,omitempty"`
	LastErrorCode  string     `json:"last_error_code,omitempty"`
	LastAttemptAt  *time.Time `json:"last_attempt_at,omitempty"`
	LastAcceptedAt *time.Time `json:"last_accepted_at,omitempty"`
}

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

func OpenReader

func OpenReader(logDir string) (*Reader, error)

func (*Reader) Load

func (r *Reader) Load() (State, error)

type Receipt

type Receipt struct {
	Provider   string    `json:"provider"`
	ExternalID string    `json:"external_id"`
	AcceptedAt time.Time `json:"accepted_at"`
}

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

func BuiltinRegistry

func BuiltinRegistry() Registry

func NewRegistry

func NewRegistry() Registry

func (Registry) Build

func (r Registry) Build(ctx context.Context, config Config) ([]Provider, error)

func (*Registry) Register

func (r *Registry) Register(name string, factory Factory) error

type SlackConfig

type SlackConfig struct {
	Enabled       bool
	WebhookURLRef string
}

func LoadSlackConfig

func LoadSlackConfig(rootDir string) (SlackConfig, error)

LoadSlackConfig loads and validates the Slack provider independently from the global notification kill switch. Webhook credentials remain typed references until a delivery attempt resolves them.

type State

type State struct {
	Schema    string              `json:"schema"`
	Incidents map[string]Incident `json:"incidents"`
	Outbox    []Envelope          `json:"outbox"`
	// LastDelivery is retained only to decode v1 state. Canonical v2 state must
	// leave it empty and use LastDeliveries instead.
	LastDelivery   DeliverySummary            `json:"last_delivery,omitempty"`
	LastDeliveries map[string]DeliverySummary `json:"last_deliveries"`
}

func EmptyState

func EmptyState() State

type StateStore

type StateStore interface {
	Load() (State, error)
	Replace(State) error
}

type Status

type Status struct {
	Enabled           bool                    `json:"enabled"`
	RepeatAfter       string                  `json:"repeat_after"`
	Providers         []ProviderStatus        `json:"providers"`
	OpenIncidents     []OpenIncidentStatus    `json:"open_incidents"`
	CoolingIncidents  []CoolingIncidentStatus `json:"cooling_incidents"`
	PendingDeliveries int                     `json:"pending_deliveries"`
}

func BuildStatus

func BuildStatus(config Config, state State) (Status, error)

type Store

type Store struct {
	// contains filtered or unexported fields
}

func OpenStore

func OpenStore(logDir string) (*Store, error)

func (*Store) Load

func (s *Store) Load() (State, error)

func (*Store) Replace

func (s *Store) Replace(state State) error

Jump to

Keyboard shortcuts

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