Complete the code to dispatch a job that will be retried on failure.
<?php
use App\Jobs\ProcessOrder;
ProcessOrder::dispatch()->[1]();The delay() method schedules the job to run after a delay, which helps in retrying failed jobs later.
Complete the code to listen for failed jobs and log the failure.
use Illuminate\Queue\Events\JobFailed;
Queue::failing(function (JobFailed $event) {
Log::error('Job failed: ' . $event->job->[1]());
});The getName() method returns the name of the failed job, useful for logging.
Fix the error in the code to retry a failed job after 10 seconds.
public function failed()
{
$this->release([1]);
}The release() method expects an integer number of seconds to delay the retry.
Fill both blanks to define a job class that handles failure by logging and releasing after delay.
class ProcessPayment implements ShouldQueue { public function failed(Exception $exception) { Log::error($exception->getMessage()); $this->[1]([2]); } }
The release(10) method retries the job after 10 seconds delay.
Fill all three blanks to create a failed job listener that logs and notifies admin.
Queue::failing(function (JobFailed $event) {
Log::error('Failed job: ' . $event->job->[1]());
Notification::route('mail', 'admin@example.com')->[2](
new JobFailedNotification($event->job, $event->exception)
);
$event->job->[3]();
});This code logs the failed job name, sends a notification, and deletes the failed job from the queue.