Agent skill
laravel-queues-jobs
Develops queued jobs and background processing. Activates when creating jobs, dispatching to queues, handling failed jobs, configuring queue workers, batching jobs, or when user mentions job, queue, dispatch, worker, background, async processing, or ShouldQueue.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/laravel-queues-jobs
SKILL.md
Laravel Queues & Jobs Development
When to Apply
Activate this skill when:
- Creating queued jobs for background processing
- Dispatching jobs to queues
- Handling job failures and retries
- Configuring queue connections and workers
- Implementing job batching or chaining
Documentation
Use search-docs for detailed Laravel queue patterns and documentation.
Basic Usage
Creating Jobs
Use Artisan to create jobs:
php artisan make:job ProcessPodcast
Job Structure
namespace App\Jobs;
use App\Models\Podcast; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Queue\Queueable;
class ProcessPodcast implements ShouldQueue { use Queueable;
public function __construct(
public Podcast $podcast,
) {}
public function handle(): void
{
// Process the podcast...
}
}
Dispatching Jobs
// Dispatch to default queue ProcessPodcast::dispatch($podcast);
// Dispatch to specific queue ProcessPodcast::dispatch($podcast)->onQueue('podcasts');
// Dispatch with delay ProcessPodcast::dispatch($podcast)->delay(now()->addMinutes(10));
// Dispatch after response sent ProcessPodcast::dispatchAfterResponse($podcast);
// Dispatch synchronously (for testing) ProcessPodcast::dispatchSync($podcast);
Job Configuration
// Max attempts before failing
public int $tries = 3;
// Max exceptions before failing
public int $maxExceptions = 3;
// Timeout in seconds
public int $timeout = 120;
// Backoff between retries (seconds)
public int $backoff = 60;
// Or exponential backoff
public array $backoff = [30, 60, 120];
// Unique job (prevents duplicates)
public function uniqueId(): string
{
return $this->podcast->id;
}
public int $uniqueFor = 3600; // Seconds
}
Handling Failures
public function handle(): void
{
// Process...
}
public function failed(?Throwable $exception): void
{
// Notify team, cleanup, etc.
Log::error('Podcast processing failed', [
'podcast_id' => $this->podcast->id,
'error' => $exception->getMessage(),
]);
}
}
Job Batching
$batch = Bus::batch([ new ProcessPodcast($podcast1), new ProcessPodcast($podcast2), new ProcessPodcast($podcast3), ])->then(function (Batch $batch) { // All jobs completed successfully })->catch(function (Batch $batch, Throwable $e) { // First batch job failure detected })->finally(function (Batch $batch) { // Batch finished (success or failure) })->dispatch();
Job Chaining
Bus::chain([ new ProcessPodcast($podcast), new OptimizePodcast($podcast), new ReleasePodcast($podcast), ])->dispatch();
Rate Limiting
public function handle(): void { Redis::throttle('podcast-processing') ->allow(10) ->every(60) ->then(function () { // Process podcast... }, function () { // Release back to queue return $this->release(30); }); }
Queue Workers
# Start worker
php artisan queue:work
# Process specific queue
php artisan queue:work --queue=high,default
# Process single job
php artisan queue:work --once
# Restart workers after code deploy
php artisan queue:restart
Failed Jobs
# View failed jobs
php artisan queue:failed
# Retry specific job
php artisan queue:retry <job-id>
# Retry all failed jobs
php artisan queue:retry all
# Delete failed job
php artisan queue:forget <job-id>
# Flush all failed jobs
php artisan queue:flush
Common Pitfalls
- Not implementing
ShouldQueueinterface (job runs synchronously) - Passing Eloquent models without serialization consideration
- Not handling job failures appropriately
- Missing
queue:restartafter deployments - Not configuring appropriate timeouts for long-running jobs
- Forgetting to set up queue worker in production (Supervisor, Horizon)
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?