delayedmessage

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package delayedmessage provides tools for delaying the sending of messages.

Index

Constants

This section is empty.

Variables

View Source
var DefaultPollInterval = 15 * time.Second

DefaultPollInterval is the duration to wait before checking for new messages to send.

Functions

This section is empty.

Types

type Interceptor

type Interceptor struct {
	Repository Repository
	Next       endpoint.OutboundPipeline
}

Interceptor is an outbound pipeline stage that intercepts messages that are not ready to be sent.

func (*Interceptor) Accept

Accept passes env to the next pipeline stage only if it is ready to send now, otherwise it stores it to be sent in the future.

func (*Interceptor) Initialize

func (i *Interceptor) Initialize(ctx context.Context, ep *endpoint.Endpoint) error

Initialize is called during initialization of the endpoint, after the transport is initialized. It can be used to inspect or further configure the endpoint as per the needs of the pipeline.

type Repository

type Repository interface {
	// LoadNextMessage loads the next that is scheduled to be sent.
	LoadNextMessage(
		ctx context.Context,
		ds persistence.DataStore,
	) (endpoint.OutboundEnvelope, bool, error)

	// SaveMessage saves a message to be sent at a later time.
	// If does NOT return an error if the message already exists in the repository.
	SaveMessage(
		ctx context.Context,
		tx persistence.Tx,
		env endpoint.OutboundEnvelope,
	) error

	// MarkAsSent marks a message as sent, removing it from the repository.
	MarkAsSent(
		ctx context.Context,
		tx persistence.Tx,
		env endpoint.OutboundEnvelope,
	) error
}

Repository is an interface for

type Sender

type Sender struct {
	DataStore        persistence.DataStore
	Repository       Repository
	OutboundPipeline endpoint.OutboundPipeline
	PollInterval     time.Duration
}

Sender is a service that sends delayed messages when they become ready to be sent.

func (*Sender) Run

func (s *Sender) Run(ctx context.Context) error

Run sends messages as they become ready to send until ctx is canceled or an error occurrs.

Jump to

Keyboard shortcuts

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