Get job-id before creating job


#1

Hello!

Is it possible to reserve a job-id before enqueue the job?
For example I want to store the job-id in the database to match specific records to the job.

Thanks!


#2

Short answer no. The job id is decided by the storage engine and as such there is no unified mechanism as to what that ID will be.

Long answer you might be able to use the job continuation mechanism to achieve your goal.

For instance I have a master job that runs every 5 minutes and consists out of 4 sub jobs. The master job enqueues the first sub job as a fire-and-forget job and sets up the 2nd, 3rd and 4th subjobs as continuations. The master job does nothing else (no functional processing that is, all of that is done in the subjobs).

To tie everything together I pass on the job id of the master job to all 4 subjobs and use that as a ‘correlation id’ for interim data generated by the subjobs in my database.

It just depends a little on what it is you are trying to do.


#3

Thanks Hans. I start only a job when it’s needed. For now I delayed the job for a few seconds as a workaround.