bullmq
bullmq copied to clipboard
[Bug]: Logging job log inside the worker completed event is throwing error
Version
v5.41.7
Platform
NodeJS
What happened?
I am trying to write logs to job on worker completed event to see the logs in bull board but at times we are getting
Error: Missing key for job 5f23d1e4-75b4-4775-8ede-30a994a21fb8. addLog at Scripts.finishedErrors (/usr/src/app/node_modules/bullmq/src/classes/scripts.ts:1568:16) at Scripts.addLog (/usr/src/app/node_modules/bullmq/src/classes/scripts.ts:570:18) at processTicksAndRejections (node:internal/process/task_queues:95:5)
Below is our code:
this.worker.on("completed", (job: Job, returnvalue: any) => { job.log(Job completed in worker jobId: ${job.id}, taskName: ${job.name}, data: ${JSON.stringify(job.data)}, queueName: ${this.queueName}); [console.info](http://console.info/)(Job completed by the worker: ${job.id}, ${job.name}, Return value: ${returnvalue}, queueName: ${this.queueName}); });
Queue Options:
{ removeOnComplete: { age: 3600, // keep up to 1 hour count: 1000, // keep up to 1000 jobs }, removeOnFail: { age: 24 * 3600, // keep up to 24 hours count: 1000 }, jobId: v4() }
Is it not okay to write logs post completion?
How to reproduce.
No response
Relevant log output
Code of Conduct
- [x] I agree to follow this project's Code of Conduct
It seems like sometimes the jobs have been auto removed faster than you think and thus the log method fails. The best is to use the log method inside the job processor, then it will work all the time.
nothing more to do here as it works as designed. Also need to await log operations as it's async