• 6 min read

Laravel Polling Jobs: #[RetryFor] and releaseUsingBackoff() in 13.43

Laravel 13.43 adds a RetryFor queue attribute and releaseUsingBackoff(). Here is how to combine them to build polling jobs that back off and expire cleanly.

Featured image for "Laravel Polling Jobs: #[RetryFor] and releaseUsingBackoff() in 13.43"

Some queued jobs do not do the work themselves. They wait for somebody else to finish it. You kick off a video transcode, a payment capture, or a report export at a third-party service, and then a job checks back every so often until the result is ready.

Laravel has always been able to do this with $this->release(), but two details were left to you: how long to wait between checks, and when to give up. Laravel 13.43, released in November 2026, adds a #[RetryFor] attribute and a releaseUsingBackoff() method that cover both. Each is small on its own. Together they make a polling job you can read in ten seconds.

The problem with polling jobs today

Say PHPTek.tv sends each conference talk recording to a transcoding service. A job polls the service until the video is ready, then publishes the talk.

Two things in the queue system work against you here.

First, releasing a job costs an attempt. The queue documentation lists a manual $this->release() as one of the ways an attempt gets consumed, and notes that Laravel only attempts a job once by default. A polling job with default settings fails on its second check.

Second, a job’s backoff is only applied by the worker when the job throws. Per the Laravel News release notes, a job that releases itself had to look up the delay by hand. In practice that meant code like this:

public function handle(TranscodeClient $client): void
{
    if (! $client->isReady($this->talk->transcode_id)) {
        $delays = [10, 30, 60, 120];
        $index = min($this->attempts() - 1, count($delays) - 1);

        $this->release($delays[$index]);

        return;
    }

    $this->talk->publish();
}

public function retryUntil(): DateTime
{
    return now()->addHours(2);
}

It works. It is also a delay table and an index calculation sitting in the middle of your business logic, plus a method whose only job is to return a timestamp.

#[RetryFor]: a retry window as an attribute

Laravel already supports time based attempts through a retryUntil() method. The docs describe it as a way to let a job be attempted any number of times within a given time frame, which is exactly what a polling job wants.

#[RetryFor], contributed by Francisco Madeira, expresses the same thing as a relative window on the class:

use Illuminate\Queue\Attributes\RetryFor;

#[RetryFor(hours: 2)]
class WaitForTalkTranscode implements ShouldQueue
{
    // ...
}

The first argument is a number of seconds, and minutes and hours can be passed by name. All of these are valid according to the docs:

#[RetryFor(90)]
#[RetryFor(minutes: 10)]
#[RetryFor(hours: 4)]
#[RetryFor(hours: 1, minutes: 30)]

A few rules worth knowing, all from the release notes and docs:

  • It works on jobs, queued mailables, queued notifications, and queued listeners.
  • Child classes inherit the attribute.
  • A retryUntil() method or $retryUntil property on the class still takes precedence over the attribute.

That last point matters during a migration. If you add the attribute to a job and forget to delete the old method, the method wins and your attribute is ignored.

releaseUsingBackoff(): reuse the schedule you already declared

The second addition, also from Francisco Madeira, lives on the InteractsWithQueue trait. Calling releaseUsingBackoff() releases the job using the delay its backoff specifies for the current attempt.

The edge cases are documented:

  • If the backoff is a list and the job has been attempted more times than the list has values, the last value is used for every later release.
  • If the job defines no backoff, it is released for immediate processing.

Watch that second one. A polling job without a #[Backoff] attribute that calls releaseUsingBackoff() will hammer the remote API as fast as the worker can pick the job back up.

Putting them together

Here is the PHPTek.tv job rewritten for 13.43:

<?php

namespace App\Jobs;

use App\Models\Talk;
use App\Services\TranscodeClient;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Queue\Attributes\Backoff;
use Illuminate\Queue\Attributes\RetryFor;
use Throwable;

#[RetryFor(hours: 2)]
#[Backoff(10, 30, 60, 120)]
class WaitForTalkTranscode implements ShouldQueue
{
    use Queueable;

    public function __construct(public Talk $talk) {}

    public function handle(TranscodeClient $client): void
    {
        if (! $client->isReady($this->talk->transcode_id)) {
            $this->releaseUsingBackoff();

            return;
        }

        $this->talk->publish();
    }

    public function failed(?Throwable $exception): void
    {
        $this->talk->update(['status' => 'transcode_timed_out']);
    }
}

Talk, TranscodeClient, and the publish() method are stand-ins for your own code. The queue parts are the two attributes and the one method call.

Read top to bottom, the class now says what it does: keep trying for two hours, wait 10 seconds, then 30, then 60, then 120 seconds between every check after that. When the window closes, the job is marked as failed and failed() gets a chance to record that the transcode never finished.

The escalating schedule is the useful part. Short videos are done in seconds, so the first checks come quickly. A long keynote settles into one request every two minutes instead of one every ten seconds for two hours.

Things to check before you rely on it

The same backoff applies to real failures. #[Backoff] is still the retry delay when the job throws, so a network error talking to the transcoder is retried on the same schedule and inside the same two hour window. That is usually what you want for a polling job, but it does mean an exception that will never succeed keeps being retried until the window closes. The docs describe a #[MaxExceptions] attribute for failing a job after a set number of unhandled exceptions, and they show it paired with #[Tries]. I would test it alongside #[RetryFor] in your own app before counting on that combination.

Delete the old method. As noted above, a leftover retryUntil() overrides the attribute silently.

Check your version. Both changes are listed as 13.x pull requests in the 13.43.0 changelog (#62434 and #62435). I did not find a 12.x backport for either in that release.

Mind Horizon. The same release declares a Composer conflict with laravel/horizon versions below 5.47.0. If you run Horizon, expect to update it in the same composer update.

Is it worth touching existing jobs?

For jobs that only use retryUntil() with a fixed offset from now(), swapping to #[RetryFor] is a one-line cleanup you can do whenever you are in the file. If the method calculates its deadline from job data, keep the method. The attribute only takes constants.

For jobs that release themselves with a hand-rolled delay table, releaseUsingBackoff() is the better win. It removes arithmetic that is easy to get wrong by one, and it puts the schedule in the same place a reader already looks for retry behavior.

Sources