Replies: 4 comments
-
A unique jobid is generated automatically which is in fact a counter, however you can pass your own jobId. However keep in mind that if there is already a job in the queue with the same id then the new job will not be added (this is useful for idempotence and debounce scenarios). |
Beta Was this translation helpful? Give feedback.
-
This doesn't explain why the id field is typed as optionnal const job= await Job.fromId(queue, id)
if (job) {
job.id // <--- typed as "id?"
} why ? |
Beta Was this translation helpful? Give feedback.
-
@daeschlerdavid All jobs have unique ids, either you let bullmq generate the id or you provide your own. That the id is optional is an implementation detail, you should never need to instantiate a Job manually but indirectly using static functions such as Job.fromId. It is probably possible to make the id non-optional, I am open to suggestions on how to improve the current design. |
Beta Was this translation helpful? Give feedback.
-
Ok. I just assumed that because the id is typed as optionnal that this field is not a reliable way to store/retrieve jobs. Currently I am using typescript non-null assertion operator to make my code compile with typescript, like this job.id! |
Beta Was this translation helpful? Give feedback.
-
Hello
When I create a new job, It is often related to something in my database (a user for example).
What is the best way for the user to find the job he created ?
It seems I need to store the job id somewhere in my db, and add my context data with it but I am not sure because :
Why is the id field "optionnal" ?
It seems to be the most important part of each job so I don't understand why it could be "undefined" .
Is it really unique ? like a redis increment ?
Is it scoped to each queue ? or global ?
Beta Was this translation helpful? Give feedback.
All reactions