deliverer

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2018 License: BSD-3-Clause Imports: 8 Imported by: 0

README

deliverer

This library is completely optional, provided only for convenience.

An extra utility that provides a simple mechanism to asynchronously deliver federated messages from a pub.Pubber available from the go-fed/activity/pub library.

It implements the pub.Deliverer interface.

The parent application may provide a way to persist delivery attempts in a way that survives shutdown by implementing the new DeliveryPersister interface. The sky is the limit.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DelivererPool

type DelivererPool struct {
	// contains filtered or unexported fields
}

func NewDelivererPool

func NewDelivererPool(d DeliveryOptions) *DelivererPool

func (*DelivererPool) Do

func (d *DelivererPool) Do(b []byte, to *url.URL, sendFn func([]byte, *url.URL) error)

Do spawns a goroutine that retries f until it returns no error. Retry behavior is determined by the DeliveryOptions passed to the DelivererPool upon construction.

func (*DelivererPool) Errors

func (d *DelivererPool) Errors() <-chan error

Provides a channel streaming any errors the pool encounters, including errors that it retries on.

func (*DelivererPool) Restart

func (d *DelivererPool) Restart(b []byte, to *url.URL, id string, sendFn func([]byte, *url.URL) error)

Restart resumes a previous attempt at delivering a payload to the specified URL. Retry behavior is determined by the DeliveryOptions passed to this DelivererPool upon construction, and is not governed by the previous DelivererPool that attempted to deliver the message.

func (*DelivererPool) Stop

func (d *DelivererPool) Stop()

Stop turns down and stops any in-flight requests or retries.

type DeliveryOptions

type DeliveryOptions struct {
	// Initial amount of time to wait before retrying delivery.
	InitialRetryTime time.Duration
	// The longest amount of time to wait before retrying delivery.
	MaximumRetryTime time.Duration
	// Rate of backing off retries. Must be at least 1.
	BackoffFactor float64
	// Maximum number of retries to do when delivering a message. Must be at
	// least 1.
	MaxRetries int
	// Global rate limiter across all deliveries, to prevent spamming
	// outbound messages.
	RateLimit *rate.Limiter
	// Persister allows implementations to save messages that are enqueued
	// for delivery between downtimes. It also permits metrics gathering and
	// monitoring of outbound messages.
	//
	// This field is optional.
	Persister DeliveryPersister
}

DeliveryOptions provides options when delivering messages to federated servers. All are required unless explicitly stated otherwise.

type DeliveryPersister

type DeliveryPersister interface {
	// Sending informs the delivery persister that the provided bytes are
	// being delivered to the specified url. It must return a unique id for
	// this delivery.
	Sending(b []byte, to *url.URL) string
	// Cancel informs the delivery persister that the provided delivery was
	// interrupted by the server cancelling. These should be retried once
	// the server is back online.
	Cancel(id string)
	// Successful informs the delivery persister that the request has been
	// successfully delivered and no further retries are needed.
	Successful(id string)
	// Retrying indicates the specified delivery is being retried.
	Retrying(id string)
	// Undeliverable indicates the specified delivery has failed and is no
	// longer being retried.
	Undeliverable(id string)
}

DeliveryPersister allows applications to keep track of delivery states of the messages being sent, including during retries. This permits clients to also resume delivery of messages that were in the process of being delivered when the application server was shut down.

Jump to

Keyboard shortcuts

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