Help us shape the future of Go! Take the 2026 Go Developer Survey

queue

package
v1.20.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DriverSync     string = "sync"
	DriverDatabase string = "database"
	DriverCustom   string = "custom"
)
View Source
const DefaultReceiveTimeout = 5 * time.Second

DefaultReceiveTimeout is the fallback timeout for a single blocking receive call made by the queue worker when the connection's configured timeout is missing, non-positive or unparsable.

Variables

This section is empty.

Functions

This section is empty.

Types

type Arg

type Arg struct {
	Value any    `json:"value"`
	Type  string `json:"type"`
}

type Args

type Args struct {
	// Specify connection
	Connection string
	// Queue specifies queue names as a comma-separated priority list,
	// consumed from left to right.
	Queue string
	// Concurrent num
	Concurrent int
	// Tries maximum attempts
	Tries int
}

type ChainJob

type ChainJob struct {
	Delay time.Time `json:"delay"`
	Job   Job       `json:"job"`
	Args  []Arg     `json:"args"`
}

type Config

type Config interface {
	config.Config
	Debug() bool
	DefaultConnection() string
	// DefaultQueue returns the first valid queue name configured for the default connection.
	// This is the queue used when dispatching a job without an explicit queue.
	DefaultQueue() string
	DefaultConcurrent() int
	Driver(connection string) string
	FailedDatabase() string
	FailedTable() string
	Via(connection string) any
	// Timeout returns the blocking receive timeout for the given connection,
	// resolved from `queue.connections.<connection>.timeout` (a number of
	// seconds, integer or fractional, or a duration string like "5s"), falling
	// back to DefaultReceiveTimeout when missing, non-positive or unparsable.
	Timeout(connection string) time.Duration
}

type Driver

type Driver interface {
	// Driver returns the driver name for the driver.
	Driver() string
	// Pop pops the next job off of the queue.
	Pop(queue string) (ReservedJob, error)
	// Push pushes the job onto the queue.
	Push(task Task, queue string) error
}

type DriverCreator

type DriverCreator interface {
	Create(connection string) (Driver, error)
}

type DriverWithReceive

type DriverWithReceive interface {
	// Receive retrieves up to count messages from the queue.
	// It may block until at least one message is available or ctx expires.
	// Returns empty slice and nil error if no messages available within deadline.
	Receive(ctx context.Context, queue string, count int) ([]ReservedJob, error)
}

DriverWithReceive is an optional interface for drivers that support batch message receiving with blocking semantics (e.g., Kafka). When a driver implements this interface, a single-queue Worker uses Receive instead of Pop for message consumption. Multi-queue Workers use Pop to preserve priority order.

type FailedJob

type FailedJob interface {
	Connection() string
	Queue() string
	FailedAt() *carbon.DateTime
	Retry() error
	Signature() string
	UUID() string
}

type Failer

type Failer interface {
	All() ([]FailedJob, error)
	Get(connection, queue string, uuids []string) ([]FailedJob, error)
}

type Job

type Job interface {
	// Signature set the unique signature of the job.
	Signature() string
	// Handle executes the job.
	Handle(args ...any) error
}

type JobStorer

type JobStorer interface {
	All() []Job
	Call(signature string, args []any) error
	Get(signature string) (Job, error)
	Register(jobs []Job)
}

type JobWithShouldRetry

type JobWithShouldRetry interface {
	// ShouldRetry determines if the job should be retried based on the error.
	// maxTries is the queue worker's configured tries: queue.Args.Tries for
	// Worker(args), or 1 for the no-argument Worker() (which hardcodes it).
	// Note that leaving Args.Tries unset passes the zero value 0; both 0 and 1
	// yield a single-shot fallback for jobs without their own retry policy.
	// Implementations without their own retry policy fall back to maxTries.
	ShouldRetry(err error, attempt, maxTries int) (retryable bool, delay time.Duration)
}

type Jobs deprecated

type Jobs = ChainJob

Deprecated: Use ChainJob instead.

type PendingJob

type PendingJob interface {
	// Delay dispatches the task after the given delay.
	Delay(time time.Time) PendingJob
	// Dispatch dispatches the task.
	Dispatch() error
	// DispatchSync dispatches the task synchronously.
	DispatchSync() error
	// OnConnection sets the connection of the task.
	OnConnection(connection string) PendingJob
	// OnQueue sets the single queue to which the task is dispatched.
	OnQueue(queue string) PendingJob
}

type Queue

type Queue interface {
	// Connection gets a driver instance by connection name
	Connection(name string) (Driver, error)
	// Chain creates a chain of jobs to be processed one by one, passing
	Chain(jobs []ChainJob) PendingJob
	// Failer gets failed jobs
	Failer() Failer
	// GetJob gets job by signature
	GetJob(signature string) (Job, error)
	// GetJobs gets all jobs
	GetJobs() []Job
	// JobStorer gets job storer
	JobStorer() JobStorer
	// Job add a job to queue
	Job(job Job, args ...[]Arg) PendingJob
	// Register register jobs
	Register(jobs []Job)
	// Worker create a queue worker
	Worker(payloads ...Args) Worker
}

type ReservedJob

type ReservedJob interface {
	// Attempts returns the number of times the job has been attempted so far.
	Attempts() int
	// Delete removes the job from the queue.
	Delete() error
	// Release makes the job available again after the given delay so it can
	// be retried, incrementing attempts on the next pop.
	Release(delay time.Duration) error
	// Task returns the task to execute.
	Task() Task
}

type Task

type Task struct {
	ChainJob
	UUID  string     `json:"uuid"`
	Chain []ChainJob `json:"chain"`
}

type Worker

type Worker interface {
	Run() error
	Shutdown() error
}

Jump to

Keyboard shortcuts

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