mailcast

package
v0.8.7 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

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 New

func New(s Store, render RenderFunc, send SendFunc, logger *slog.Logger) *Runner

New builds a Runner with conservative defaults.

func (*Runner) Cancel

func (r *Runner) Cancel(ctx context.Context, id string) error

Cancel stops a broadcast: unsent recipients are marked cancelled.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, id string) error

Run sends every pending recipient of a broadcast, returning when done, cancelled or ctx ends.

func (*Runner) Start

func (r *Runner) Start(parent context.Context, id string)

Start runs a broadcast in the background; a second Start for the same id is a no-op.

func (*Runner) Tick

func (r *Runner) Tick(ctx context.Context, now time.Time)

Tick starts every scheduled broadcast that is due and resumes any that were interrupted while sending. Call it on an interval.

type SendFunc

type SendFunc func(ctx context.Context, m email.Message) error

SendFunc delivers one message.

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.

Jump to

Keyboard shortcuts

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