Install via Composer:
composer require vendor/package-name
The package now fully supports Laravel 8.x, including native job features like tries, retryUntil, backoff, batch, timeout, and maxExceptions. For first use, check the updated docs for Laravel 8 compatibility and test with a simple job:
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class ExampleJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function handle()
{
// Job logic
}
// New Laravel 8 features
public function retryUntil()
{
return now()->addMinutes(5);
}
public function backoff()
{
return 10; // seconds
}
}
Dispatch via dispatch() or dispatchNow().
Retry Logic:
Use retryUntil() to dynamically set retry deadlines (e.g., for transient failures).
public function retryUntil()
{
return now()->addMinutes($this->maxRetries * 2);
}
Exponential Backoff:
Implement backoff() to delay retries exponentially (e.g., for rate-limited APIs).
public function backoff()
{
return $this->attempts() * 1000; // Milliseconds
}
Batch Processing:
Use batch() to group jobs (e.g., for bulk operations).
ExampleJob::dispatch($data)->batch(ExampleJob::class);
Timeouts:
Set timeout() to fail jobs after inactivity (default: 60 seconds).
public function timeout()
{
return 300; // Seconds
}
Exception Handling:
Limit failures with maxExceptions() (e.g., for non-recoverable errors).
public function maxExceptions()
{
return 3;
}
php artisan queue:work) is running with --sleep=3 for optimal backoff handling.HandleFailures) to log retries or trigger alerts.queue:failed to track job progress and failures.composer require laravel/framework:^8.0
ShouldQueue, ensure all traits (Dispatchable, InteractsWithQueue, etc.) are updated to Laravel 8’s versions.Retry Loops:
failed_jobs table for retry attempts. Use queue:flush to clear stale jobs during testing.attempts() in handle() to verify retry counts:
\Log::info("Attempt #{$this->attempts()}");
Backoff Delays:
QUEUE_CONNECTION=sync to bypass delays, then switch to database/redis for real backoff behavior.Batch Quirks:
onQueue() to separate critical batches:
ExampleJob::dispatch()->onQueue('high_priority')->batch(ExampleJob::class);
Custom Retry Logic:
Override retryUntil() dynamically (e.g., based on job payload):
public function retryUntil()
{
return $this->payload['retryDeadline'] ?? now()->addMinute();
}
Queue Events:
Listen for job.processing, job.failed, or job.released events to hook into the retry lifecycle:
event(new JobProcessing(ExampleJob::class, $job));
Testing:
Use Queue::fake() with assertProcessed()/assertFailed() to verify retries:
$job = ExampleJob::dispatch();
Queue::fake();
$job->fail(new \Exception('Test'));
Queue::assertProcessed(ExampleJob::class);
How can I help you explore Laravel packages today?