Install
$ agentstack add skill-kwhorne-elyra-skills-laravel-queue-design ✓ scanned · ✓ verified — works with Claude Code, Cursor, and more.
Security review
✓ PassedNo issues found. Passed automated security review. · v0.1.0 How review works →
- ✓ Prompt-injection patterns
- ✓ Secret / credential exfiltration
- ✓ Dangerous shell & filesystem operations
- ✓ Untrusted network calls
- ✓ Known-malicious package signatures
What it can access
- ✓ Network access No
- ✓ Filesystem access No
- ✓ Shell / process execution No
- ✓ Environment & secrets No
- ✓ Dynamic code execution No
From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.
About
Laravel Queue Design
A queued job will run twice, run late, or run after the world changed under it. Design every job for those three facts and production gets boring — in the good way.
When to use
- Creating or reviewing queued jobs, listeners, or notifications
- "Jobs are stuck / duplicated / silently failing"
- Moving slow work (mail, exports, API calls) out of the request
- Setting up or tuning Horizon / queue workers
Principles
- At-least-once means duplicates. Every handler must tolerate running twice — idempotency is the entry fee, not a nice-to-have.
- Small payload, fresh state. Pass IDs, re-fetch inside the job. The world at dispatch time is not the world at run time.
- Failure is a feature. Decide per job what retry, backoff, and final failure mean — the defaults are guesses.
- One job, one outcome. A job that does five things fails five ways and retries all of them.
Process
1. Design the job
class ProcessRefund implements ShouldQueue
{
public function __construct(public int $orderId) {} // ID, not model state you'll trust later
public $tries = 3;
public $backoff = [10, 60, 300]; // seconds; spread retries out
public $timeout = 120; // must be orderId); // fresh state
if ($order->refunded) return; // idempotency check
// ...
}
}
- Eloquent models in constructors are fine (
SerializesModelsre-fetches), but decisions made on dispatch-time state are stale — re-check conditions inhandle() $timeoutrefunded) return;` — re-read, then act- Unique jobs:
ShouldBeUniqueto prevent duplicate dispatch - DB constraint: unique index +
firstOrCreate/upsert absorbs the duplicate - External calls: pass an idempotency key to the payment/API provider
3. Decide the failure story
failed(Throwable $e)method: notify, mark the domain object, compensate- Don't retry the unretryable: validation-type failures →
$this->fail($e)immediately - Poison-pill protection:
$tries/$maxExceptionsso one bad payload doesn't loop forever - Monitor
failed_jobs— a table nobody looks at is a black hole. Alert on growth;queue:retryafter fixing the cause
4. Compose bigger work
| Need | Tool | |---|---| | Steps in order, abort on failure | Job chain (Bus::chain) | | Fan-out N items + completion hook | Batch (Bus::batch(...)->then(...)->catch(...)) | | Per-tenant/user serialization | WithoutOverlapping middleware | | External API rate limits | RateLimited middleware, dedicated queue |
For batches: items must be independently retryable; allowFailures() if one bad item shouldn't sink the batch.
5. Separate queues by SLA
high(user-facing: mail verification, receipts),default,low(exports, sync)- Workers:
--queue=high,default,lowpriority order, or dedicated workers per queue - One slow queue must not starve fast ones — that's the whole point of separation
6. Operate it
- Horizon: balance/processes per queue, alert on wait time, watch failed rate
- Deploys:
queue:restart(workers hold old code in memory until restarted) - Track queue wait time (latency from dispatch to start) — it's the user-facing number
Output format
## Queue review:
| Job | Idempotent via | tries/backoff | timeout: →
### Queue topology
high: …, default: …, low: … — workers: …
Anti-patterns
- ❌ Serializing a model and trusting its attributes at run time (stale decisions)
- ❌
$timeout≥retry_after— concurrent double execution by design - ❌ Default retries on a non-idempotent job touching money
- ❌ One giant job processing 10 000 rows instead of a batch of small ones
- ❌
failed_jobsas a write-only table with no alerting - ❌ Forgetting
queue:restarton deploy, then debugging "old code" for an hour - ❌ Everything on the
defaultqueue — exports starving password-reset mails
Source & license
This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.
- Author: kwhorne
- Source: kwhorne/elyra-skills
- License: MIT
- Homepage: https://elyracode.com
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet — be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.