Documentation ¶
Index ¶
- Constants
- Variables
- type DB
- type Message
- type SendFunc
- type Status
- type StatusFunc
- type Throttle
- type ThrottleConfig
- type ThrottleConfigBuilder
- func (b *ThrottleConfigBuilder) AddRules(rules []ThrottleRule)
- func (b *ThrottleConfigBuilder) Config() ThrottleConfig
- func (b *ThrottleConfigBuilder) WithDestTypes(destTypes ...string) *ThrottleConfigBuilder
- func (b *ThrottleConfigBuilder) WithMsgTypes(msgTypes ...gadb.EnumOutgoingMessagesType) *ThrottleConfigBuilder
- type ThrottleItem
- type ThrottleRule
- type ThrottleRules
Constants ¶
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 ¶
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 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, a *alertlog.Store, pausable lifecycle.Pausable) (*DB, error)
NewDB creates a new DB.
func (*DB) SendMessages ¶
SendMessages will send notifications using SendFunc.
func (*DB) UpdateMessageStatus ¶
func (db *DB) UpdateMessageStatus(ctx context.Context, status *notification.SendResult) error
UpdateMessageStatus will update the state of a message.
type Message ¶
type Message struct { ID string Type gadb.EnumOutgoingMessagesType DestID notification.DestID Dest gadb.DestV1 AlertID int AlertLogID int VerifyID string UserID string ServiceID string ScheduleID string CreatedAt time.Time SentAt time.Time StatusAlertIDs []int64 }
Message represents the data for an outgoing message.
type SendFunc ¶
type SendFunc func(context.Context, *Message) (*notification.SendResult, error)
SendFunc defines a function that sends messages.
type StatusFunc ¶
type StatusFunc func(ctx context.Context, providerID notification.ProviderMessageID) (*notification.Status, error)
StatusFunc is used to fetch the latest status of a message.
type Throttle ¶ added in v0.27.0
type Throttle struct {
// contains filtered or unexported fields
}
Throttle represents the throttled messages for a queue.
func NewThrottle ¶ added in v0.27.0
func NewThrottle(cfg ThrottleConfig, now time.Time, byTypeOnly bool) *Throttle
NewThrottle creates a new Throttle used to manage outgoing messages in a queue.
func (*Throttle) InCooldown ¶ added in v0.27.0
InCooldown returns true or false depending on the cooldown state of a throttled message.
type ThrottleConfig ¶ added in v0.27.0
type ThrottleConfig interface { Rules(Message) []ThrottleRule MaxDuration() time.Duration }
ThrottleConfig provides ThrottleRules for a given message.
var GlobalCMThrottle ThrottleConfig = ThrottleRules{{Count: 5, Per: 5 * time.Second}}
GlobalCMThrottle represents the rate limits for each notification type.
var PerCMThrottle ThrottleConfig
PerCMThrottle configures rate limits for individual contact methods.
type ThrottleConfigBuilder ¶ added in v0.27.0
type ThrottleConfigBuilder struct {
// contains filtered or unexported fields
}
ThrottleConfigBuilder can be used to build advanced throttle configurations.
func (*ThrottleConfigBuilder) AddRules ¶ added in v0.27.0
func (b *ThrottleConfigBuilder) AddRules(rules []ThrottleRule)
AddRules will append a set of rules for the current filter (if any).
func (*ThrottleConfigBuilder) Config ¶ added in v0.27.0
func (b *ThrottleConfigBuilder) Config() ThrottleConfig
Config will return a ThrottleConfig for the current top-level configuration.
func (*ThrottleConfigBuilder) WithDestTypes ¶ added in v0.27.0
func (b *ThrottleConfigBuilder) WithDestTypes(destTypes ...string) *ThrottleConfigBuilder
WithDestTypes allows adding rules for messages matching at least one DestType.
func (*ThrottleConfigBuilder) WithMsgTypes ¶ added in v0.27.0
func (b *ThrottleConfigBuilder) WithMsgTypes(msgTypes ...gadb.EnumOutgoingMessagesType) *ThrottleConfigBuilder
WithMsgTypes allows adding rules for messages matching at least one MessageType.
type ThrottleItem ¶ added in v0.27.0
type ThrottleItem struct { DestHash gadb.DestHashV1 BucketDur time.Duration }
ThrottleItem represents the messages being throttled.
type ThrottleRule ¶ added in v0.27.0
type ThrottleRule struct { Count int Per time.Duration // Smooth indicates that the rule should impose a rate limit over the entire duration. Smooth bool }
ThrottleRule sets the number of messages allowed to be sent per set duration.
type ThrottleRules ¶ added in v0.27.0
type ThrottleRules []ThrottleRule
ThrottleRules is a collection of ThrottleRule that implements the ThrottleConfig interface.
func (ThrottleRules) MaxDuration ¶ added in v0.27.0
func (rs ThrottleRules) MaxDuration() time.Duration
MaxDuration returns the longest `Per` value for the set of rules.
func (ThrottleRules) Rules ¶ added in v0.27.0
func (rs ThrottleRules) Rules(Message) []ThrottleRule
Rules always returns the set of configured rules for all messages.