notifier

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package notifier encapsulates the concept of sending a common.Notification via some Transport

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Permanent

func Permanent(err error) error

Permanent wraps the given err as a permanent error which should not be retried

Types

type BackOff added in v0.3.0

type BackOff = backoff.BackOff

type BackOffFactory added in v0.3.0

type BackOffFactory = func() BackOff

type DefaultNotifier

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

DefaultNotifier is the default implementation of the Notifier interface It routes notifications to the appropriate transport based on the user's preferences

func New

func New(userStore user.Store, transports ...Transport) *DefaultNotifier

New creates a new DefaultNotifier

func (*DefaultNotifier) Push

func (d *DefaultNotifier) Push(ctx context.Context, notification common.Notification) error

type Func

Func is a function that sends a notification

type Notifier

type Notifier interface {
	// Push sends a notification, either immediately or enqueued for later delivery
	// It SHOULD return an error wrapped by Permanent if we know that retries will never succeed
	Push(context.Context, common.Notification) error
}

Notifier is an interface for sending notifications Implementations of this interface may send them to a Transport, enqueue them for later, batch multiple notifications together, etc. Using the decorator design pattern to add functionality to a Notifier is encouraged! (https://refactoring.guru/design-patterns/decorator)

func NewNotifier

func NewNotifier(pushFunc Func) Notifier

NewNotifier creates a new Notifier from a push function

type Transport

type Transport interface {
	Notifier
	// Key returns a unique identifier for this transport, useful for routing purposes
	Key() common.TransportKey
}

Transport is any notifier with a distinct, named key. The key is used to route notifications to the correct transport. You will typically have one Transport implementation per notification service. For example: one for Slack, another for email, etc.

func NewTransport

func NewTransport(key common.TransportKey, pushFunc Func) Transport

NewTransport creates a new Transport from a key and a push function

func WithLogging

func WithLogging(transport Transport, logger *slog.Logger, logLevel slog.Level) Transport

WithLogging decorates the given Transport and logs every successful push (including the message body)

func WithRetry

func WithRetry(transport Transport, maxTries uint, backoffFactory BackOffFactory) Transport

WithRetry decorates the given Transport with retry logic using the provided backoff

func WithTimeout

func WithTimeout(transport Transport, timeout time.Duration) Transport

WithTimeout decorates the given Transport with a timeout

type WriterNotifier

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

WriterNotifier is a notifier that simply writes notifications somewhere, like a file or stdout It is primarily used for testing and debugging

func NewWriterNotifier

func NewWriterNotifier(key common.TransportKey, writer io.Writer) *WriterNotifier

NewWriterNotifier creates a Notifier that writes notifications to places like files or stdout

func (*WriterNotifier) Key

func (*WriterNotifier) Push

Directories

Path Synopsis
Package slack provides a notifier.Transport implementation for sending notifications to Slack
Package slack provides a notifier.Transport implementation for sending notifications to Slack

Jump to

Keyboard shortcuts

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