By default, Laravel retries a failed job automatically based on the retry limit configured in the queue worker or the job's own retryUntil method. If the job exceeds the retry limit, it is then moved to the failed_jobs table.
When a job exceeds its retry limit, Laravel moves it to the failed_jobs table. This allows developers to review and handle failed jobs later.
Laravel uses the backoff method to specify the number of seconds to wait before retrying a failed job.
public function handle() {
throw new \Exception('Fail');
}
public function retryUntil() {
return now()->addSeconds(30);
}
public function backoff() {
return 10;
}
public function failed() {
// Log failure
}For Laravel to retry jobs, the job class must implement the ShouldQueue interface. Without it, the job runs immediately and does not retry on failure.
Laravel calls the failed() method on a job class when it has failed all retry attempts. This is the ideal place to add custom failure handling like sending alert emails.