0
0
Laravelframework~10 mins

Job retries and failure 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 specify the maximum number of retries for a Laravel job.

Laravel
public $tries = [1];
Drag options to blanks, or click blank then click option'
A5
B1
C10
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Setting $tries to 0 disables retries, which may not be intended.
Using a string instead of an integer for $tries.
2fill in blank
medium

Complete the code to define the method that runs when a job fails in Laravel.

Laravel
public function [1](\Exception $exception)
{
    // Handle the failure
}
Drag options to blanks, or click blank then click option'
AhandleFailure
Bfailed
ConFail
DfailJob
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method name that Laravel does not recognize for failure handling.
Not including the exception parameter.
3fill in blank
hard

Fix the error in the code to release the job back to the queue after a delay on failure.

Laravel
public function failed(\Exception $exception)
{
    $this->release([1]);
}
Drag options to blanks, or click blank then click option'
A5
Bnow()
Cdelay()
D'5 seconds'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string instead of an integer causes errors.
Using a function call like now() which returns a DateTime object.
4fill in blank
hard

Fill both blanks to define a job that should be retried 4 times and fails after 60 seconds delay.

Laravel
public $tries = [1];

public function failed(\Exception $exception)
{
    $this->release([2]);
}
Drag options to blanks, or click blank then click option'
A4
B3
C60
D30
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the retry count and delay values.
Using strings instead of integers.
5fill in blank
hard

Fill all three blanks to create a job that retries 2 times, releases after 45 seconds on failure, and logs the exception message.

Laravel
public $tries = [1];

public function failed(\Exception $exception)
{
    $this->release([2]);
    \Log::error([3]);
}
Drag options to blanks, or click blank then click option'
A2
B45
C$exception->getMessage()
D60
Attempts:
3 left
💡 Hint
Common Mistakes
Not calling getMessage() on the exception.
Using incorrect delay values or retry counts.