← Back to Website builders
See how it helps
Laravel queues and events
Runs background work with explicit retries, durable outcomes and clean transaction and tenant boundaries.
laravel-queues-events
Team members using this skill
When is it useful?
Use when exports, notifications or integrations should execute outside the request lifecycle.
What does it help you do?
- Makes jobs safe against duplicate dispatch and sets bounded timeout and retry behavior.
- Dispatches dependent work after commit and handles missing or changed records.
- Prevents long-lived workers from carrying tenant or authentication state into another job.
Try asking this
Build an export job that survives duplicate delivery and worker restart while preserving each tenant's scope and failure status. Run exports for two tenants sequentially in the same worker and redeliver one job. Produce one scoped artifact per job without leaking earlier tenant context.
Detailed documentation
Read the skill’s original instructions, examples and checks in their authored language.
Show less
Queues, Events & Scheduler
Queued jobs, retries and idempotency
- Offload slow or external work (emails, webhooks, third-party APIs, exports, media processing) to
ShouldQueuejobs. Never treat a queued job or event listener as guaranteed to run exactly once. - Make every job idempotent: guard side effects with state checks, unique database constraints, idempotency keys or
ShouldBeUnique, so retries or duplicate dispatches never double-charge, double-send or corrupt records. - Set explicit
$tries,$backoff(array of seconds),$timeoutand$maxExceptions, and implementfailed(\Throwable $e)to record permanent failure and clean up partial state. - Ensure the queue connection's
retry_afterinconfig/queue.phpis strictly greater than the job's$timeout; otherwise a worker can pick up a second copy while the first is still running.
Payloads, transactions and worker state
- Pass Eloquent models (via
SerializesModels, which stores only the model identifier and re-queries on execution) or scalar IDs — never serialize large collections, request objects or binary blobs into the queue payload. Handle deleted or stale models cleanly when the job runs. - When dispatching a job or event inside a database transaction (or from a model observer), implement
ShouldDispatchAfterCommitor call->afterCommit()so workers never read uncommitted rows. - In long-lived queue workers (
queue:work, Horizon, Octane), never leak static state, singleton properties, auth state or tenant context from one job or request into the next. Explicitly pass and restore tenant context per job, and note when a deploy requiresphp artisan queue:restart.
Events, notifications and scheduler
- Use Events and Listeners to decouple domain side effects from the primary action, and Notifications (
ShouldQueue) for user-facing messages across mail, database or Slack channels. - Keep scheduled closures/commands in
routes/console.php(orapp/Console/Kernel.phpin Laravel 10) thin by delegating to services or jobs. Add->withoutOverlapping()on tasks that could run past their interval and->onOneServer()in multi-server deployments.
Included files 2
LICENSE.txtSKILL.md
