bull-prom icon indicating copy to clipboard operation
bull-prom copied to clipboard

Add protection if job is null

Open phoenix741 opened this issue 2 years ago • 0 comments

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

phoenix741 avatar Mar 20 '22 10:03 phoenix741