bull-prom
bull-prom copied to clipboard
Add protection if job is null
Hello,
Can you add a protection to check the job is not null ?
[api] 2022-03-20T09:54:56.617Z [ ] error: uncaughtException: Cannot read properties of null (reading 'finishedOn')
[api] TypeError: Cannot read properties of null (reading 'finishedOn')
[api] at recordJobMetrics (/home/phoenix/Developpement/Shadoware.Org/Software/woodstock-backup/nestjs/node_modules/bull-prom/lib/index.js:79:18)
[api] at Object.<anonymous> (/home/phoenix/Developpement/Shadoware.Org/Software/woodstock-backup/nestjs/node_modules/bull-prom/lib/index.js:98:17)
[api] at Generator.next (<anonymous>)
[api] at fulfilled (/home/phoenix/Developpement/Shadoware.Org/Software/woodstock-backup/nestjs/node_modules/bull-prom/lib/index.js:5:58)
[api] at processTicksAndRejections (node:internal/process/task_queues:96:5)
I use the parameter useGlobal in the following case, the job (getJob) can be null (in case of a delay between the event and the process of the event)
if (useGlobal) {
queue.on('global:completed', async (jobId: number) => {
const job = await queue.getJob(jobId);
recordJobMetrics(labels, JobStatus.COMPLETED, job);
});
queue.on('global:failed', async (jobId: number) => {
const job = await queue.getJob(jobId);
recordJobMetrics(labels, JobStatus.FAILED, job)
})
} else {
Thanks