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 ¶
- func CloudFailedJobs(ctx context.Context, url string, encrypter *crypt.Encrypter, ...) ([]queue.FailedJob, error)
- func IsCloudURL(id string) bool
- func Retried(ctx context.Context, cloud config.Cloud, logger *slog.Logger, ...)
- type CloudDriver
- func (d *CloudDriver) Clear(ctx context.Context, queue string) (int64, error)
- func (d *CloudDriver) Push(ctx context.Context, queue string, payload []byte, delay time.Duration) error
- func (d *CloudDriver) PushBulk(ctx context.Context, queue string, payloads [][]byte) error
- func (d *CloudDriver) Reserve(ctx context.Context, queues []string) (queue.Reserved, error)
- func (d *CloudDriver) Sizes(ctx context.Context, queue string) (queue.Sizes, error)
- type Driver
- func (d *Driver) Clear(ctx context.Context, queue string) (int64, error)
- func (d *Driver) Push(ctx context.Context, queue string, payload []byte, delay time.Duration) error
- func (d *Driver) PushBulk(ctx context.Context, queue string, payloads [][]byte) error
- func (d *Driver) Reserve(ctx context.Context, queues []string) (queue.Reserved, error)
- func (d *Driver) Sizes(ctx context.Context, name string) (queue.Sizes, error)
- type Options
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 ¶
IsCloudURL reports whether id, passed to queue:retry, is a Laravel Cloud dashboard URL for stored failed jobs.
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 ¶
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 ¶
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 ¶
PushBulk sends payloads to queue in SQS and emits a queued event for each payload to Laravel Cloud.
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.
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
}