sqsqueue

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 22 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package sqsqueue provides queue.Driver implementations for Amazon SQS (Driver) and Laravel Cloud managed queues (CloudDriver).

Applications configure an sqs connection in config.Queue.Connections, and Laravel Cloud automatically wires a cloud connection. To construct a driver directly:

driver := sqsqueue.New(cfg.Queue.SQS, sqsqueue.Options{Cache: appCache})

SQS tracks each job's attempt count through ApproximateReceiveCount, which is approximate, so a job may occasionally run one more or one fewer time than its configured Tries. Releasing a job updates its message visibility timeout (up to SQS's 12-hour limit from initial receipt) so the job keeps its attempt count and queue position. Because SQS delays a message for at most 15 minutes, longer delays are wrapped in an envelope recording the target availability time and re-sent in hops of up to 15 minutes.

A FIFO queue (whose name ends in .fifo) executes jobs within each message group sequentially in dispatch order. Because SQS FIFO queues do not support per-message delays and a delayed job would block its group, pushing a delayed job to a FIFO queue returns an error.

SQS limits message bodies to 1 MiB. When overflow is enabled in config.SQS, larger payloads are stored in Options.Cache for 14 days and the SQS message carries only the cache key.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloudFailedJobs

func CloudFailedJobs(ctx context.Context, url string, encrypter *crypt.Encrypter, client *http.Client) ([]queue.FailedJob, error)

CloudFailedJobs fetches and decrypts all paginated failed jobs from url on the Laravel Cloud dashboard using encrypter. If client is nil, a default HTTP client with a 10-second timeout is used.

func IsCloudURL

func IsCloudURL(id string) bool

IsCloudURL reports whether id, passed to queue:retry, is a Laravel Cloud dashboard URL for stored failed jobs.

func Retried

func Retried(ctx context.Context, cloud config.Cloud, logger *slog.Logger, job queue.FailedJob)

Retried notifies Laravel Cloud's event socket that a failed job stored in the dashboard has been re-dispatched onto its queue.

Types

type CloudDriver

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

CloudDriver is a queue.Driver, queue.BulkPusher, and queue.Sizer for Laravel Cloud managed queues backed by SQS. Single-queue workers pull jobs through the Laravel Cloud runtime agent when configured, and multi-queue workers poll SQS directly. CloudDriver emits job lifecycle events to Laravel Cloud's event socket and sends permanently failed jobs to the Laravel Cloud dashboard instead of the application's failed jobs table.

func NewCloud

func NewCloud(sqs config.SQS, cloud config.Cloud, options Options) *CloudDriver

NewCloud returns a *CloudDriver for Laravel Cloud managed queues using the SQS settings in sqs, the agent and event socket addresses in cloud, and options.

func (*CloudDriver) Clear

func (d *CloudDriver) Clear(ctx context.Context, queue string) (int64, error)

Clear purges all messages from queue in SQS and returns the approximate number of removed jobs.

func (*CloudDriver) Push

func (d *CloudDriver) Push(ctx context.Context, queue string, payload []byte, delay time.Duration) error

Push sends payload to queue in SQS and emits a queued event to Laravel Cloud.

func (*CloudDriver) PushBulk

func (d *CloudDriver) PushBulk(ctx context.Context, queue string, payloads [][]byte) error

PushBulk sends payloads to queue in SQS and emits a queued event for each payload to Laravel Cloud.

func (*CloudDriver) Reserve

func (d *CloudDriver) Reserve(ctx context.Context, queues []string) (queue.Reserved, error)

Reserve claims the next available job from the Laravel Cloud agent when a single queue is polled and the agent is configured, or directly from SQS when polling multiple queues. It emits a started event on success.

func (*CloudDriver) Sizes

func (d *CloudDriver) Sizes(ctx context.Context, queue string) (queue.Sizes, error)

Sizes returns approximate message counts for queue from SQS.

type Driver

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

Driver is an Amazon SQS-backed queue.Driver, queue.BulkPusher, and queue.Sizer. Queues must already exist in AWS before pushing or reserving jobs.

func New

func New(cfg config.SQS, options Options) *Driver

New returns a *Driver configured from cfg and options. When cfg.Credentials omits static keys, requests are signed with the default AWS credential chain, such as an IAM task or instance role.

func (*Driver) Clear

func (d *Driver) Clear(ctx context.Context, queue string) (int64, error)

Clear purges all messages from queue using SQS PurgeQueue (which AWS limits to once per 60 seconds) and returns the approximate number of jobs reported before purging.

func (*Driver) Push

func (d *Driver) Push(ctx context.Context, queue string, payload []byte, delay time.Duration) error

Push sends payload to queue in SQS so it becomes available after delay. It returns an error if delay is positive on a FIFO queue or if payload exceeds 1 MiB without overflow enabled.

func (*Driver) PushBulk

func (d *Driver) PushBulk(ctx context.Context, queue string, payloads [][]byte) error

PushBulk sends payloads to queue in order using SQS SendMessageBatch requests of up to 10 messages and 1 MiB each. It stops and returns an error at the first batch that SQS does not accept in full so no later job is sent ahead of a failed one.

func (*Driver) Reserve

func (d *Driver) Reserve(ctx context.Context, queues []string) (queue.Reserved, error)

Reserve receives the next available message from the first non-empty queue in queues, re-enqueuing any multi-hop delayed messages that are not yet due. It returns nil with a nil error when no message is available.

func (*Driver) Sizes

func (d *Driver) Sizes(ctx context.Context, name string) (queue.Sizes, error)

Sizes returns SQS's approximate pending, delayed, and reserved message counts for name. OldestPending is always the zero time.Time because SQS does not expose the oldest message's dispatch time in queue attributes.

type Options

type Options struct {
	// Cache stores payloads that exceed SQS's 1 MiB limit when overflow is
	// enabled. Use a cache store shared by all web and worker processes.
	Cache *cache.Cache
	// Logger receives driver warnings. If nil, [New] uses [slog.Default].
	Logger *slog.Logger
	// Client executes HTTP requests to SQS. If nil, [New] uses
	// [http.DefaultClient].
	Client *http.Client
}

Options provides runtime dependencies for New and NewCloud.

Jump to

Keyboard shortcuts

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