Documentation
¶
Overview ¶
Package mailcast sends broadcasts: a queue of per-recipient messages processed in rate-limited batches, resumable after a restart and cancellable while sending.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RenderFunc ¶
type RenderFunc func(ctx context.Context, b store.MailBroadcast, r store.MailRecipient) (email.Message, error)
RenderFunc builds the message for one recipient.
type Runner ¶
type Runner struct {
Store Store
Render RenderFunc
Send SendFunc
Logger *slog.Logger
// Delay is the pause between two messages, the sending rate limit.
Delay time.Duration
// Batch is how many recipients are loaded between status re-checks.
Batch int
// SendTimeout bounds one message.
SendTimeout time.Duration
// contains filtered or unexported fields
}
Runner drives broadcasts. Create it with New.
func (*Runner) Run ¶
Run sends every pending recipient of a broadcast, returning when done, cancelled or ctx ends.
type Store ¶
type Store interface {
GetMailBroadcast(ctx context.Context, id string) (*store.MailBroadcast, error)
UpdateMailBroadcast(ctx context.Context, b store.MailBroadcast) error
UpdateMailBroadcastProgress(ctx context.Context, id string, sent, failed, suppressed int) error
FinishMailBroadcast(ctx context.Context, b store.MailBroadcast) error
ListMailBroadcastsByStatus(ctx context.Context, statuses ...string) ([]store.MailBroadcast, error)
ListMailRecipients(ctx context.Context, broadcastID, status string, limit int) ([]store.MailRecipient, error)
SetMailRecipientStatus(ctx context.Context, broadcastID, email, status, errText string) error
CancelPendingMailRecipients(ctx context.Context, broadcastID string) error
ListMailSuppressions(ctx context.Context) ([]store.MailSuppression, error)
}
Store is the persistence the runner needs; *store.DB satisfies it.
Click to show internal directories.
Click to hide internal directories.