message

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2020 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StatusPending means the message is waiting to be sent.
	StatusPending = Status("pending")

	// StatusSending means the message is in the process of being sent upstream
	StatusSending = Status("sending")

	// StatusQueuedRemotely means the message has been sent upstream, but is in a remote queue.
	StatusQueuedRemotely = Status("queued_remotely")

	// StatusSent means the message has been sent upstream, and has left the remote queue (if one exists).
	StatusSent = Status("sent")

	// StatusDelivered will be set on delivery if the upstream supports delivery confirmation.
	StatusDelivered = Status("delivered")

	// StatusFailed means the message failed to send.
	StatusFailed = Status("failed")

	// StatusStale is used if the message expired before being sent.
	StatusStale = Status("stale")
)

Defined status values

Variables

View Source
var ErrAbort = errors.New("aborted due to pause")

ErrAbort is returned when an early-abort is returned due to pause.

Functions

This section is empty.

Types

type Config

type Config struct {
	// MaxMessagesPerCycle determines the number of pending messages
	// fetched per-cycle for delivery.
	//
	// Defaults to 50.
	MaxMessagesPerCycle int

	// RateLimit allows configuring rate limits per contact-method type.
	RateLimit map[notification.DestType]*RateConfig

	// Pausable is optional, and allows early-abort of
	// message sending when IsPaused returns true.
	Pausable lifecycle.Pausable
}

Config is used to configure the message sender.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default configuration.

type DB

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

DB implements a priority message sender using Postgres.

func NewDB

func NewDB(ctx context.Context, db *sql.DB, c *Config, a alertlog.Store) (*DB, error)

NewDB creates a new DB. If config is nil, DefaultConfig() is used.

func (*DB) SendMessages

func (db *DB) SendMessages(ctx context.Context, send SendFunc, status StatusFunc) error

SendMessages will send notifications using SendFunc.

func (*DB) UpdateMessageStatus

func (db *DB) UpdateMessageStatus(ctx context.Context, status *notification.MessageStatus) error

UpdateMessageStatus will update the state of a message.

type Message

type Message struct {
	ID         string
	Type       Type
	Dest       notification.Dest
	AlertID    int
	AlertLogID int
	VerifyID   string

	UserID    string
	ServiceID string
	CreatedAt time.Time
	SentAt    time.Time

	StatusAlertIDs []int
}

Message represents the data for an outgoing message.

type RateConfig

type RateConfig struct {
	// PerSecond determines the target messages-per-second limit.
	PerSecond int

	// Batch sets how often granularity of the rate limit.
	Batch time.Duration
}

RateConfig allows setting egress rate limiting on messages.

type SendFunc

SendFunc defines a function that sends messages.

type Status

type Status string

Status represents the current state of an outgoing message.

func (Status) IsSent

func (s Status) IsSent() bool

IsSent returns true if the message has been successfully sent to the downstream server.

type StatusFunc

type StatusFunc func(ctx context.Context, id, providerMsgID string) (*notification.MessageStatus, error)

StatusFunc is used to fetch the latest status of a message.

type Type

type Type string

Type represents the purpose of a message in the outgoing messages queue.

const (
	TypeAlertNotification       Type = "alert_notification"
	TypeTestNotification        Type = "test_notification"
	TypeVerificationMessage     Type = "verification_message"
	TypeAlertStatusUpdate       Type = "alert_status_update"
	TypeAlertNotificationBundle Type = "alert_notification_bundle"
	TypeAlertStatusUpdateBundle Type = "alert_status_update_bundle"
)

defined message types

Jump to

Keyboard shortcuts

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