queue

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectMostOf

func CollectMostOf[T any](ctx context.Context, count int) func(iter.Seq2[T, error]) iter.Seq2[T, error]

func IteratorIsEmpty

func IteratorIsEmpty[T any](
	iterator iter.Seq2[T, error],
) func(*testing.T)

func MountSenders

func MountSenders(
	r *message.Router,
	pub message.Publisher,
	sub message.Subscriber,
	topicPrefix string,
	senders ...mdsend.Mailer,
)

TODO: deprecate?

func NewConfirmationHandler

func NewConfirmationHandler(
	q Queue,
	s Confirmer,
	m Marshaler,
) message.NoPublishHandlerFunc

func NewContinuousScanner

func NewContinuousScanner(
	ctx context.Context,
	wg *errgroup.Group,
	q Queue,
	s Scheduler,
	options ContinuousScannerOptions,
)

func NewProgressTracker

func NewProgressTracker(
	q Queue,
	report ProgressTracker,
) interface {
	Queue
	Confirmer
}

func NewSender

func NewSender(s mdsend.Mailer) message.HandlerFunc

func QueueRecognizesDuplicates

func QueueRecognizesDuplicates(q Queue) func(*testing.T)

func TestQueue

func TestQueue(q Queue) func(*testing.T)

Types

type ChildCursor

type ChildCursor struct {
	ParentID string
	Cursor
}

type Confirmation

type Confirmation struct {
	ID        string
	LetterID  string
	MessageID string
	SentAt    time.Time
}

type Confirmer

type Confirmer interface {
	ConfirmScheduling(context.Context, Confirmation) error
}

type ConfirmerFunc

type ConfirmerFunc func(context.Context, Confirmation) error

func (ConfirmerFunc) ConfirmScheduling

func (f ConfirmerFunc) ConfirmScheduling(ctx context.Context, c Confirmation) error

type ContinuousScannerOptions

type ContinuousScannerOptions struct {
	Frequency             time.Duration
	LetterBatchSize       uint8
	MessageBatchSize      uint16
	BeginWithOlderLetters bool
	Logger                *slog.Logger
}

type Cursor

type Cursor struct {
	ItemID string
	Batch  int64
}

Cursor holds the position of an item in a list from which an iterator can retrieve items sequentially. If Cursor.ItemID is empty, the iterator starts from the first batch. The item with the same ID is always skipped, so the iterator will start from the next item.

Cursor.Batch sets the maximum number of items to retrieve in one repository paging operation. A negative batch value iterates items in descending order from the Cursor.ItemID.

The iterator loads additional batches as needed as long as the range of items to retrieve is not exhausted.

Context cancellation will stop the iterator at the end of the current batch.

type Marshaler

type Marshaler interface {
	MarshalMessage(any) (*message.Message, error)
	UnmarshalMessage(*message.Message, any) error
}

func NewMarshalerJSON

func NewMarshalerJSON() Marshaler

type Process

type Process interface {
	JoinErrorGroup(context.Context, *errgroup.Group, Queue)
}

type Progress

type Progress struct {
	Sent    int64
	Total   int64
	Average time.Duration
}

func (Progress) EstimateRemaining

func (p Progress) EstimateRemaining() time.Duration

func (Progress) LogValue

func (p Progress) LogValue() slog.Value

func (Progress) MessagesPerMinute

func (p Progress) MessagesPerMinute() int64

func (Progress) MessagesPerSecond

func (p Progress) MessagesPerSecond() int64

func (Progress) OfOne

func (p Progress) OfOne() float64

func (Progress) String

func (p Progress) String() string

type ProgressTracker

type ProgressTracker interface {
	TrackProgress(context.Context, Progress)
}

type ProgressTrackerFunc

type ProgressTrackerFunc func(context.Context, Progress)

func (ProgressTrackerFunc) TrackProgress

func (f ProgressTrackerFunc) TrackProgress(ctx context.Context, p Progress)

type Publisher

type Publisher interface {
	Publish(context.Context, mdsend.Message) error
}

func NewRoundRobinPublisher

func NewRoundRobinPublisher(publisher message.Publisher, prefix string, count uint) Publisher

type Queue

type Queue interface {
	CreateLetter(context.Context, mdsend.Letter) error
	RetrieveLetter(context.Context, string) (mdsend.Letter, error)
	MarkLetterAsSent(context.Context, string) (bool, error)
	DeleteLetter(context.Context, string) error

	CreateAttachment(context.Context, mdsend.Attachment) error
	CreateMessage(context.Context, mdsend.Message) error
	MarkMessagesAsScheduled(context.Context, string, ...string) error
	MarkMessageAsSent(context.Context, string) (bool, error)

	ListLetters(context.Context, Cursor) iter.Seq2[mdsend.Letter, error]
	ListMessages(context.Context, ChildCursor) iter.Seq2[mdsend.Message, error]
	ListAttachments(context.Context, string) iter.Seq2[mdsend.Attachment, error]

	BeginTransaction(context.Context) (Queue, Transaction, error)
	WithTransaction(context.Context, Transaction) (Queue, error)
}

type Scheduler

type Scheduler interface {
	ScheduleForDelivery(context.Context, mdsend.Letter, []mdsend.Message) error
}

func NewRoundRobinScheduler

func NewRoundRobinScheduler(schedulers ...Scheduler) Scheduler

NewRoundRobinScheduler rotates through the provided schedulers on each scheduled messsage.

func NewSchedulerForPublisher

func NewSchedulerForPublisher(q Queue, m Marshaler, pub message.Publisher, topic string) Scheduler

NewSchedulerForPublisher returns a basic transaction-less scheduler. It marks the messsage as queued first to avoid duplicate deliveries. If the publisher fails to publish, the message is dropped. The sacrifice of consistency allows the scheduler to use the queue and publisher that do not use a compatible database driver.

Queue drivers sometimes provide a stricter scheduler.

type SchedulerFunc

type SchedulerFunc func(context.Context, mdsend.Letter, []mdsend.Message) error

func (SchedulerFunc) ScheduleForDelivery

func (f SchedulerFunc) ScheduleForDelivery(
	ctx context.Context,
	letter mdsend.Letter,
	batch []mdsend.Message,
) error

type Transaction

type Transaction interface {
	Close(*error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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