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

IncomingTH's avatar

Dispatch a job with delay from a job with delay increase the delay?

Hi,

I have this weird behavior where I resubmit the job from itself with a delay of 30s, the delay seems to stack for each runs. The class looks like this:

class MyJob implements ShouldQueue
{
...
	public function handle() {
		...
		dispatch(new MyJob ($this->model))->delay(now()->addSeconds(30));
		...
	}
}

But it seems that for each iteration when the job is waiting for something, the previous delay is added to the new delay. So if it was first run no issue it's 30 seconds delay, but second run will be 60 seconds, 3rd run will be 90 seconds, etc.

I cannot use $this->release() by the way, because the job can run/try for hours as it is checking for something to happen (and yes I could make the change to have the completed event to trigger the job dispatch but that's not the main question).

Is that normal behavior or is something is fishy here?

Thanks

0 likes
3 replies
Snapey's avatar

I do similar and it works perfectly. My method of dispatch is slightly different, and I space the jobs at 10 minute intervals

class AdviseP44Job implements ShouldQueue
{

//

   if(empty($drop->TrackingATA) && $this->limit > 0) {

            AdviseP44Job::dispatch (
                    $this->consignments, 
                    $this->drop_id,
                    $this->limit-1
                )->delay(now()->addMinutes(10));
        }
        

$this->limit is a counter for the max execution iterations and is passed along from one job to the next

1 like
IncomingTH's avatar

@Snapey Thanks, this seems very similar indeed, except that I do not use the limit but I doubt it is changing anything at least for my case as we dispatch a new job, not releasing the same back to the queue, so the retry/limit is untouched.

Therefore, the problem could be something else from Horizon maybe.

I can see the jobs in queue, I have added just right after the handle() method a log to check if they are run, but nothing is logged despite the delay increasing. Meaning the job are not processed (for unknown reason) but just added back to the queue with delay increasing.

Also, it seems after 15 minutes the jobs are processing fine. Never had this issue before upgrading to Laravel as far as I remember.

Snapey's avatar

@IncomingTH make sure the initial job ends and the new job is queued. These should be separate independent jobs and the first terminates normally, straight after despatching a new copy (or not)

Please or to participate in this conversation.