Production Laravel · 8 min read · Intermediate
Queues, Background Jobs & Scheduled Tasks
Offload slow work like emails, webhooks, and PDF rendering to background queue workers.
What you'll learn
- Implement `ShouldQueue` jobs with `$tries` and backoff retries
- Run queue workers reliably under Supervisor in production
- Schedule recurring maintenance tasks in `routes/console.php`
Overview
Offload slow work like emails, webhooks, and PDF rendering to background queue workers.
Code Example
<?php
namespace App\Jobs;
use App\Models\Certificate;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
class SendCertificateEmail implements ShouldQueue {
use Queueable;
public int $tries = 3;
public function __construct(public Certificate $certificate) {}
public function handle(): void {
// Mail::to($this->certificate->email)->send(...);
}
}
Key Takeaways
- Implement
ShouldQueuejobs with$triesand backoff retries - Run queue workers reliably under Supervisor in production
- Schedule recurring maintenance tasks in
routes/console.php
Quick Check
Check Your Understanding
Score: 0 / 1
1. Why should sending transactional emails or generating large PDFs run on a Laravel Queue?
Study Workspace
Finished this lesson?
Your progress is saved locally in your browser, no account needed.