What is the `#[FailOnTimeout]` attribute used for in Laravel 13?

In Laravel 13, the #[FailOnTimeout] attribute is used to specify that if a queued job exceeds its defined timeout limit, it should be marked as failed immediately instead of being retried.

It is the new declarative, attribute-based replacement for the traditional class property public bool $failOnTimeout = true;. This is particularly useful in distributed workloads to prevent the system from wasting resources on unnecessary retries when a job times out.

Example

To use it, you need to import the attribute and place it above your job class:

use IlluminateContractsQueueShouldQueue;
use IlluminateQueueAttributesFailOnTimeout;
use IlluminateQueueAttributesTimeout;

#[Timeout(120)]
#[FailOnTimeout]
class ProcessPodcast implements ShouldQueue
{
   // ...
}
In this example, if the ProcessPodcast job runs for more than 120 seconds, it will be immediately marked as failed and will not be placed back into the retry queue.

 

7 Views