queues-jobs-notifications

Implements Laravel queued jobs and mail notifications with multi-tenant context reinjection.

Updated May 5, 2025
One-click install
npx skills add https://github.com/sebauvray/toollab-api --skill queues-jobs-notifications-sebauvray
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: queues-jobs-notifications
Source: https://github.com/sebauvray/toollab-api/tree/main/.claude/skills/queues-jobs-notifications
Command: npx skills add https://github.com/sebauvray/toollab-api --skill queues-jobs-notifications-sebauvray

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Asynchronous jobs and queued notifications in a multi-tenant Laravel app lose the HTTP request context, causing global scopes to return zero rows, duplicate job executions, and emails that never send. This Skill documents the exact patterns to create, dispatch, and debug jobs and mail notifications safely in the Toollab codebase. ## Core Features & Use Cases - Job creation patterns: Enforces context reinjection of school and school-year IDs inside handle(), afterCommit() dispatching, idempotency via transition checks, and passing integer IDs instead of serialized models. - Notification conventions: Covers the 6 existing Mailable notifications, ShouldQueue with $tries = 3 and $backoff = [60, 300, 900], Blade email templates, and the dual URL bases (app.url for images, app.frontend_url for links). - Debugging playbook: Diagnoses common failures such as missing queue workers in dev, retry_after shorter than job $timeout, stale serialized payloads, and broken logos in Gmail. - Use Case: When a payment completion email never arrives in development, use this Skill to check that a queue worker is running, verify Maildev on port 1080, and confirm the job reinjects tenant context. ## Quick Start Ask the assistant to create a new queued Laravel job and notification following the Toollab multi-tenant context reinjection pattern.

Frequently Asked Questions about queues-jobs-notifications

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a queued job in Laravel with multi-tenant scoping?▼

Implement ShouldQueue with Dispatchable, InteractsWithQueue, Queueable, and SerializesModels traits, pass an integer ID rather than a model, and reload the record with withoutGlobalScopes. Inside handle(), set current_school_id and current_school_year_id on request attributes and restore them in a finally block.

How do I queue a Laravel notification with retry and backoff?▼

Make the notification implement ShouldQueue, use the Queueable trait, and set public $tries = 3 with public $backoff = [60, 300, 900] for retries at 1, 5, and 15 minutes. Add $this->afterCommit = true in the constructor when the notification is triggered inside a database transaction.

Why does my Laravel queued job return zero database rows?▼

Queued jobs run outside the HTTP request, so request attributes are empty and tenant global scopes fail closed, returning zero rows. Reinject the school and school-year IDs into request attributes at the start of handle() and restore the previous values in a finally block.

Why is my Laravel job executed twice by the queue worker?▼

The job runs twice when retry_after (90 seconds here) is shorter than the job's $timeout, so the queue assumes it failed and redispatches it while still running. Increase DB_QUEUE_RETRY_AFTER above the longest job timeout before raising any $timeout value.

Why is my queued email not sending in Laravel development?▼

No queue worker runs by default in the dev environment, so queued mails stay in the jobs table. Run php artisan queue:work --once to drain one job, and confirm Maildev is active on port 1025 with its UI at http://localhost:1080.

Should I pass Eloquent models or IDs to Laravel queued jobs?▼

Pass integer IDs and reload the model explicitly with withoutGlobalScopes inside the job. SerializesModels re-resolves models through global scopes before tenant context is restored, which can silently fail or resolve the wrong record in multi-tenant applications.