0
0
Laravelframework~10 mins

Failed job handling in Laravel - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to dispatch a job that will be retried on failure.

Laravel
<?php
use App\Jobs\ProcessOrder;

ProcessOrder::dispatch()->[1]();
Drag options to blanks, or click blank then click option'
Adelay
BonQueue
CallOnQueue
Dretry
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'retry' method which does not exist on dispatch.
Confusing 'onQueue' with retry behavior.
2fill in blank
medium

Complete the code to listen for failed jobs and log the failure.

Laravel
use Illuminate\Queue\Events\JobFailed;

Queue::failing(function (JobFailed $event) {
    Log::error('Job failed: ' . $event->job->[1]());
});
Drag options to blanks, or click blank then click option'
AgetJobId
BgetName
CgetQueue
DgetConnectionName
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'getJobId' which returns an ID, not the job name.
Using 'getQueue' which returns the queue name, not the job.
3fill in blank
hard

Fix the error in the code to retry a failed job after 10 seconds.

Laravel
public function failed()
{
    $this->release([1]);
}
Drag options to blanks, or click blank then click option'
A'10 seconds'
Bnow()->addSeconds(10)
C10
D10 * 1000
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string like '10 seconds' causes errors.
Passing a DateTime object instead of seconds.
4fill in blank
hard

Fill both blanks to define a job class that handles failure by logging and releasing after delay.

Laravel
class ProcessPayment implements ShouldQueue
{
    public function failed(Exception $exception)
    {
        Log::error($exception->getMessage());
        $this->[1]([2]);
    }
}
Drag options to blanks, or click blank then click option'
Arelease
Bdelete
C10
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'delete' instead of 'release' will remove the job.
Using too small or string delay values.
5fill in blank
hard

Fill all three blanks to create a failed job listener that logs and notifies admin.

Laravel
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]();
});
Drag options to blanks, or click blank then click option'
AgetName
Bnotify
Cdelete
Drelease
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'release' instead of 'delete' will retry the job.
Using wrong method names for notification.