laravel-queues
Laravel 13 queue and job patterns — driver choice, job design (idempotency, ShouldQueue, model serialisation), retry and failure handling, worker scaling, Bus batching and chaining, Horizon when warranted, queue testing. Use when designing async jobs, scheduling background work, configuring Horizon, debugging stuck jobs, or auditing queue health. Triggers on "Laravel queue", "Laravel job", "background job", "Horizon setup", "failed jobs", "Bus batch", "queue worker tuning".
- License 许可
- MIT
- 最近更新
- 2026-09-01
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- laravel-queues
- license
- MIT
- metadata
- { "author": "agent-skills", "version": "1.0.0" }
- description
- Laravel 13 queue and job patterns — driver choice, job design (idempotency, ShouldQueue, model serialisation), retry and failure handling, worker scaling, Bus batching and chaining, Horizon when warranted, queue testing. Use when designing async jobs, scheduling background work, configuring Horizon, debugging stuck jobs, or auditing queue health. Triggers on "Laravel queue", "Laravel job", "background job", "Horizon setup", "failed jobs", "Bus batch", "queue worker tuning".
02 资源文件 24
- 参考文档AGENTS.md95.6 KB
- 参考文档README.md1.9 KB
- 参考文档rules/_sections.md2.1 KB
- 参考文档rules/_template.md642 B
- 参考文档rules/bus-batch-failure-handling.md5.1 KB
- 参考文档rules/bus-batch-vs-chain.md5.4 KB
- 参考文档rules/bus-chunking-large-sets.md5.2 KB
- 参考文档rules/config-after-commit.md3.7 KB
- 参考文档rules/config-driver-choice.md4.1 KB
- 参考文档rules/config-failed-storage.md4.7 KB
- 参考文档rules/design-constructor-vs-handle.md5.0 KB
- 参考文档rules/design-idempotency.md5.1 KB
- 参考文档rules/design-pass-ids-not-models.md5.0 KB
- 参考文档rules/design-shouldqueue.md4.2 KB
- 参考文档rules/ops-horizon-when.md5.1 KB
- 参考文档rules/ops-queue-fake.md6.2 KB
- 参考文档rules/ops-schedule-queued-jobs.md5.8 KB
- 参考文档rules/retry-fail-on-timeout.md4.8 KB
- 参考文档rules/retry-failed-method.md4.7 KB
- 参考文档rules/retry-transient-vs-permanent.md5.2 KB
- 参考文档rules/retry-tries-and-backoff.md4.6 KB
- 参考文档rules/scaling-multi-queue-priority.md5.1 KB
- 参考文档rules/scaling-supervisor-config.md5.3 KB
- 参考文档rules/scaling-worker-recycling.md4.3 KB
03 SKILL.md 正文
Laravel Queues & Jobs
Production-grade queue patterns for Laravel 13 (MySQL + Redis). Contains 20 rules across 6 categories covering driver choice, job design, retry/failure handling, worker scaling, batching/chaining, and testing. Targets the failure modes that pass code review but break under load — silent re-dispatch on retry, models stale on serialisation, missing idempotency on payment jobs, workers leaking memory, and "we forgot ShouldQueue and the request takes 12 seconds in production."
Metadata
- Version: 1.0.0
- Scope: PHP / Laravel 13 + MySQL + Redis (queues), optional Horizon
- Rule Count: 20 rules across 6 categories
- License: MIT
How to Use
When the user asks "design this background job", "audit our queue setup", "why is this job not running", or anything queue-related — work through this skill's rules as a checklist against the relevant files (job classes, config/queue.php, config/horizon.php, supervisor config, the dispatching call sites).
For audit mode, output per-rule verdicts:
- PASS — pattern correctly applied
- FAIL — anti-pattern present (with file:line + fix recommendation)
- N/A — does not apply to this codebase
End with a top-priority fix list (idempotency on payment jobs, missing ShouldQueue, supervisor stopwaitsecs too low — these are the most common production-bite issues).
When to Apply
Reference this skill when:
- Writing a new background job (
php artisan make:job) - Reviewing a PR that adds or modifies a job class
- Setting up queue workers on a new server (Forge / Vapor / bare server)
- Configuring
config/queue.phporconfig/horizon.php - Debugging a stuck, looping, or repeatedly-failing job
- Choosing between
dispatch(),dispatchSync(),dispatchAfterResponse(),Bus::batch(),Bus::chain() - Adding queue testing (
Queue::fake(),Bus::fake()) - Deciding whether to adopt Horizon
Step 1: Detect Queue Setup
Inspect:
| File | What to learn |
|---|---|
config/queue.php |
Default connection (QUEUE_CONNECTION env), failed-jobs storage, after_commit setting |
config/horizon.php (if present) |
Horizon environments, balance strategy, worker counts, timeouts |
app/Jobs/*.php |
Job classes, ShouldQueue usage, tries/backoff, failed() methods |
app/Console/Kernel.php or routes/console.php |
Scheduled jobs (Schedule::job(...), withoutOverlapping) |
database/migrations/*_create_failed_jobs_table.php |
Failed-jobs storage migration; or DynamoDB driver in config |
supervisor*.conf / /etc/supervisor/conf.d/ |
Worker process management, numprocs, --max-time, stopwaitsecs |
Typical setups:
| Stack | Queue driver | Failed driver | Worker manager |
|---|---|---|---|
| Small Laravel + MySQL | database |
database |
Supervisor (or systemd) |
| Production Laravel + Redis | redis |
database (or dynamodb for serverless) |
Supervisor + Horizon |
| Laravel Vapor | sqs |
dynamodb |
Vapor-managed |
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Driver & Config | CRITICAL | config- |
| 2 | Job Design | CRITICAL | design- |
| 3 | Retry & Failure | HIGH | retry- |
| 4 | Scaling & Workers | HIGH | scaling- |
| 5 | Batching & Chaining | HIGH | bus- |
| 6 | Testing & Operations | MEDIUM | ops- |
Quick Reference
1. Driver & Config (CRITICAL)
config-driver-choice—databasefor small apps;redisfor production scale;sqsfor Laravel Vaporconfig-after-commit— setafter_commit: trueto prevent dispatching jobs that reference uncommitted DB rowsconfig-failed-storage—failed_jobstable is required (or DynamoDB on Vapor); set up retention/cleanup
2. Job Design (CRITICAL)
design-shouldqueue— every async job MUST implementShouldQueue(the #1 production bug: forgetting it makes the job run synchronously)design-pass-ids-not-models— pass IDs to the constructor; refetch inhandle()— avoids stale models and bloated serialised payloadsdesign-idempotency— payment, external API, and "create resource" jobs must be safe to run twice (ShouldBeUnique, idempotency keys, unique DB constraints)design-constructor-vs-handle— constructor runs at dispatch (sync);handle()runs on the worker. No DB writes or HTTP calls in the constructor.
3. Retry & Failure (HIGH)
retry-tries-and-backoff— set both:#[Backoff([1, 5, 30])]for exponential delays; default 3 tries is usually too few for transient failuresretry-failed-method— implementfailed(Throwable $e)for permanent-failure handling (alert, refund, mark-as-failed)retry-transient-vs-permanent—release($delay)for transient errors (rate-limited, network); throw for permanentretry-fail-on-timeout—#[FailOnTimeout]to avoid burning all attempts on hung jobs
4. Scaling & Workers (HIGH)
scaling-supervisor-config— Supervisor (or systemd) manages workers;stopwaitsecs > timeout;--max-time=3600to recyclescaling-multi-queue-priority— high/default/low queue lanes for SLA-critical jobs;--queue=high,default,lowscaling-worker-recycling—--max-jobsand--max-timeto combat memory leaks in long-running workers
5. Batching & Chaining (HIGH)
bus-batch-vs-chain—Bus::batchfor parallel + progress tracking;Bus::chainfor strict sequentialbus-batch-failure-handling—allowFailures()for fault-tolerant batches; usethen/catch/finallycallbacksbus-chunking-large-sets— for 1000+ items, chunk viaBus::batch(...)rather than one job per item
6. Testing & Operations (MEDIUM)
ops-queue-fake—Queue::fake()/Bus::fake()in tests;assertDispatched,assertPushed,assertChained,assertBatchedops-schedule-queued-jobs—Schedule::job(new X)->everyMinute()queues the job; pair withwithoutOverlapping()for safetyops-horizon-when— adopt Horizon when on Redis with multiple supervisors; not fordatabasequeue or single-worker setups
Essential Patterns
Minimum-viable job class (Laravel 13)
<?php
namespace App\Jobs;
use App\Models\Order;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\Attributes\Backoff;
use Illuminate\Queue\Attributes\FailOnTimeout;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Throwable;
#[Backoff([1, 5, 30])]
#[FailOnTimeout]
class ChargeOrder implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public int $tries = 5;
public int $timeout = 30;
public function __construct(public readonly int $orderId) {}
public function handle(StripeGateway $stripe): void
{
$order = Order::findOrFail($this->orderId); // refetch — don't trust serialised state
if ($order->status === 'paid') return; // idempotency guard
$charge = $stripe->charge($order);
$order->markPaid($charge->id);
}
public function failed(Throwable $e): void
{
Order::find($this->orderId)?->markPaymentFailed($e->getMessage());
}
}
Dispatching
ChargeOrder::dispatch($order->id); // default queue
ChargeOrder::dispatch($order->id)->onQueue('high'); // priority lane
ChargeOrder::dispatch($order->id)->delay(now()->addMinutes(5));
ChargeOrder::dispatchAfterResponse($order->id); // run after HTTP response sent
Supervisor config (recommended)
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/app/artisan queue:work redis --queue=high,default,low --sleep=3 --tries=3 --max-time=3600 --backoff=3
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=forge
numprocs=8
redirect_stderr=true
stdout_logfile=/var/www/app/storage/logs/worker.log
stopwaitsecs=3600
Critical: stopwaitsecs must be greater than your longest job's timeout, or Supervisor will kill mid-job on deploy.
References
- Laravel 13 — Queues
- Laravel 13 — Horizon
- Laravel 13 — Task Scheduling
- Supervisor — A Process Control System
Full Compiled Document
For the complete guide with all rules expanded: AGENTS.md
04 同仓库更多 Skills
wordpress-pro
Develops custom WordPress themes and plugins, creates and registers Gutenberg blocks and block patterns, configures WooCommerce stores, implements WordPress REST API endpoints, applies security hardening (nonces, sanitization, escaping, capability checks), and optimizes performance through caching and query tuning. Use when building WordPress themes, writing plugins, customizing Gutenberg blocks, extending WooCommerce, working with ACF, using the WordPress REST API, applying hooks and filters, or improving WordPress performance and security.
websocket-engineer
Use when building real-time communication systems with WebSockets or Socket.IO. Invoke for bidirectional messaging, horizontal scaling with Redis, presence tracking, room management.
webapp-testing
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.
web-design-guidelines
UI/UX best practices and accessibility audit. Use when reviewing UI code, checking accessibility, running accessibility audits, auditing forms, or ensuring web interface best practices. Triggers on "audit accessibility", "check WCAG", "review UI", "check accessibility", "audit design", "review UX", or "check best practices".
web-artifacts-builder
Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn/ui). Use for complex artifacts requiring state management, routing, or shadcn/ui components - not for simple single-file HTML/JSX artifacts.
vue-expert
Builds Vue 3 components with Composition API patterns, configures Nuxt 3 SSR/SSG projects, sets up Pinia stores, scaffolds Quasar/Capacitor mobile apps, implements PWA features, and optimises Vite builds. Use when creating Vue 3 applications with Composition API, writing reusable composables, managing state with Pinia, building hybrid mobile apps with Quasar or Capacitor, configuring service workers, or tuning Vite configuration and TypeScript integration.