queue

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrStarted means the queue has already been started.
	ErrStarted = errors.New("queue already started")
	// ErrNotStarted means the queue has not been started yet.
	ErrNotStarted = errors.New("queue not started")
	// ErrCanceled means a job has been canceled by either calling job.Cancel() or by canceling it's context.
	ErrCanceled = errors.New("job canceled")
	// ErrFinished means a job has already been finished and can therefore not be canceled.
	ErrFinished = errors.New("job already finished")
)

Functions

This section is empty.

Types

type Job

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

Job is a queue job.

func (*Job) Cancel

func (j *Job) Cancel(ctx context.Context) error

Cancel the job. If the job is already finished, Cancel() returns ErrFinished.

func (*Job) Config added in v0.9.3

func (j *Job) Config() dispatch.Config

Config returns the job's dispatch.Config.

func (*Job) Context

func (j *Job) Context() context.Context

Context returns the job's context that has been passed to the (*Queue).Dispatch() method.

func (*Job) DispatchedAt

func (j *Job) DispatchedAt() time.Time

DispatchedAt returns the time at which j was dispatched.

func (*Job) Done

func (j *Job) Done() <-chan struct{}

Done returns a channel that's closed when the job is done. After the returned channel has been closed, j.Err() returns either nil or an error if the job failed.

func (*Job) Err

func (j *Job) Err() error

Err returns a non-nil error if the job failed.

func (*Job) Mail

func (j *Job) Mail() postdog.Mail

Mail returns the queued mail.

func (*Job) Runtime

func (j *Job) Runtime() time.Duration

Runtime returns the current runtime time.Now().Sub(j.DispatchedAt()) if the job isn't done yet. Otherwise it returns the total duration between j.DispatchedAt() and the time the job has completed.

type Mailer

type Mailer interface {
	SendConfig(context.Context, postdog.Mail, send.Config) error
}

Mailer is an interface for *postdog.Dog.

type Option

type Option func(*Queue)

Option is a queue option.

func Buffer

func Buffer(s int) Option

Buffer returns an Option that sets the buffer size of a *Queue.

func Workers

func Workers(w int) Option

Workers returns an Option that sets the worker count of a *Queue.

type Queue

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

Queue is the mailer queue.

func New

func New(m Mailer, opts ...Option) *Queue

New returns a new *Queue that sends mails through the Mailer m.

func (*Queue) Dispatch

func (q *Queue) Dispatch(ctx context.Context, m postdog.Mail, opts ...dispatch.Option) (*Job, error)

Dispatch adds m to q and returns the queue *Job, or an error if the dispatch failed.

func (*Queue) DispatchConfig added in v0.9.2

func (q *Queue) DispatchConfig(ctx context.Context, m postdog.Mail, cfg dispatch.Config) (*Job, error)

DispatchConfig does the same as Dispatch() but accepts a dispatch.Config instead if dispatch.Options.

func (*Queue) Start

func (q *Queue) Start() error

Start the queue workers in a new goroutine.

func (*Queue) Started

func (q *Queue) Started() bool

Started determines if the queue has been started.

func (*Queue) Stop

func (q *Queue) Stop(ctx context.Context) error

Stop the queue. If the queue has not been started yet, Stop() returns ErrNotStarted. If ctx is canceled before the remaining jobs have been processed, Stop() returns ctx.Err().

Directories

Path Synopsis
Package mock_queue is a generated GoMock package.
Package mock_queue is a generated GoMock package.

Jump to

Keyboard shortcuts

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