Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lechicken's avatar

(Laravel 8) retryUntil() method in Job is ignored when job is chained

HI,

I tested out the retryUntil() method to fully understand when it works and how it works and I found that it is completely ignored when the job with this method is defined in a chained job. Not sure if this is expected behaviour, I couldn't find anything about it in the docs. Also not sure if this is a bug in Laravel 8 fixed in other versions.

I have 3 testJob's: PullRepo RunTests Deploy

They are chained as follows:

Route::get('/job', function (){

    $chain = [
        new PullRepo(),
        new RunTests(),
        new Deploy()
    ];

    \Illuminate\Support\Facades\Bus::chain($chain)->dispatch();

    return view('welcome');
});

This is the last job in the chain (Deploy):

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;


class Deploy implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $tries = -1;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        sleep(2);
    }

    public function retryUntil()
    {
        return now()->addSecond(1);
    }

}

When dispatched in a chain:

php artisan queue:work
[2023-10-11 07:58:48][6948] Processing: App\Jobs\PullRepo
[2023-10-11 07:58:50][6948] Processed:  App\Jobs\PullRepo
[2023-10-11 07:58:50][6949] Processing: App\Jobs\RunTests
[2023-10-11 07:58:52][6949] Processed:  App\Jobs\RunTests
[2023-10-11 07:58:52][6950] Processing: App\Jobs\Deploy
[2023-10-11 07:58:54][6950] Processed:  App\Jobs\Deploy

Now let's dispatch the job without chaining:

Route::get('/job', function (){

    (new Deploy)->dispatch();

    return view('welcome');
});

Only in this case it will fail:

php artisan queue:work
[2023-10-11 08:03:53][6953] Processing: App\Jobs\Deploy
[2023-10-11 08:03:53][6953] Failed:     App\Jobs\Deploy

I haven't tested yet if the $tries property is also ignore. It could be that that is the one being ignored which makes the retryUntil() method not function. I have no clue.

Thanks for your help

0 likes
1 reply

Please or to participate in this conversation.