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

VETO87's avatar

Dispatch Queue Job with Delay and Get Job ID

Hello,

I'm currently working on a Laravel 10 project where I have a unique requirement in my job processing logic. Within a job, I perform an API check to determine the status of an order. If the order status is not 'delivered', I use the $this->release($this->getNextDelay()); function to requeue the job with a delay, intending to send another API request at a later time.

Problem

My issue arises with tracking the job IDs for these delayed jobs. When I call $this->job->getJobId();, it returns the ID of the current job instance, which is expected. However, I need to obtain the ID of the newly created delayed job (the job instance created by $this->release()).

Is there a way in Laravel 10 to retrieve the job ID of a job that has been requeued using $this->release? Any guidance or workaround to track these delayed job IDs would be greatly appreciated.

0 likes
4 replies
Snapey's avatar

why should you need the id? It does not seem related to your requirements?

VETO87's avatar

@Snapey basically I want to allow staffs in my panel to delete some scheduleTasks that have job_id columns

When they check the scheduleTasks they see button to delete which basically retrieves the job using the job_id

But the problem is the job_id is not correct its the current job that the scheduleTask was created on not the delayed one.

Snapey's avatar

@VETO87 Rather than release the job, create a new job and dispatch that from within the first job?

Snapey's avatar

Alternatively, add a timestamp column to the order to say when its next check is due.

Have a scheduled task that regularly checks for any orders that have a check due. Then the scheduled task can fire the API job.

If the user wants to cancel or defer the check, just set the next check value on the order to false or a future time.

This way you never need to track any job IDs

Please or to participate in this conversation.