queue

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: Apache-2.0 Imports: 3 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsServerError added in v0.9.2

func IsServerError(err error) bool

func Retry

func Retry(taskFunc TaskFunc, options ...RetryOption)

Types

type BackoffFunc

type BackoffFunc func(int) time.Duration

type Queue

type Queue interface {

	// Push adds a new task to the Queue.  The queue is expected to
	// process the task asynchronously, and return immediately.
	Push(task Task)
}

Queue is an interface that wraps the Push method.

func NewSimpleQueue

func NewSimpleQueue(workers int, maxLength int, options ...RetryOption) Queue

NewSimpleQueu returns a fully initialized SimpleQueue, which will process tasks in the background until the Close() method is called.

type RetryConfig

type RetryConfig struct {
	ReportErrors bool
	MaxAttempts  int
	Backoff      BackoffFunc
}

RetryConfig contains configuration options for how a Retry operation should be handled

func NewRetryConfig

func NewRetryConfig(options ...RetryOption) RetryConfig

NewRetryConfig creates a new RetryConfig with default values and applies additional optional function parameters as provided

func (*RetryConfig) With

func (config *RetryConfig) With(options ...RetryOption)

With applies one or more options to a RetryConfig

type RetryOption

type RetryOption func(*RetryConfig)

RetryOption is a function that modifies a RetryConfig

func WithExponentialBackoff

func WithExponentialBackoff() RetryOption

WithExponentialBackoff is a RetryOption that sets the backoff function to an exponential curve

func WithLinearBackoff

func WithLinearBackoff() RetryOption

WithLinearBackoff is a RetryOption that sets the backoff function to a linear curve

func WithMaxAttempts

func WithMaxAttempts(maxAttempts int) RetryOption

WithMaxAttempts is a RetryOption that sets the maximum number of attempts to retry a task

func WithReportErrors

func WithReportErrors() RetryOption

WithReportErrors is a RetryOption that sets whether or not errors should be reported to the error log

type SimpleQueue

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

Simple is a perfectly workable in-memory queue that uses a buffered channel to store tasks and multiple goroutines as task runners.

Some day it may make sense to use a ring buffer, but today is not that day https://bravenewgeek.com/so-you-wanna-go-fast/ https://github.com/Workiva/go-datastructures/blob/master/queue/ring.go

func (*SimpleQueue) Close

func (q *SimpleQueue) Close()

Close shuts down all of the queue workers.

func (*SimpleQueue) Push

func (q *SimpleQueue) Push(task Task)

Push adds a task to the queue

type Task

type Task interface {
	Run() error
}

Task is an interface that wraps the Run method. Tasks are fed into the queue and processed asynchronously.

type TaskFunc

type TaskFunc func() error

Jump to

Keyboard shortcuts

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