diff --git a/lib/index.js b/lib/index.js index 00591ab..bc7148e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -95,11 +95,15 @@ function init(opts) { if (useGlobal) { queue.on('global:completed', (jobId) => __awaiter(this, void 0, void 0, function* () { const job = yield queue.getJob(jobId); - recordJobMetrics(labels, JobStatus.COMPLETED, job); + if (job) { + recordJobMetrics(labels, JobStatus.COMPLETED, job); + } })); queue.on('global:failed', (jobId) => __awaiter(this, void 0, void 0, function* () { const job = yield queue.getJob(jobId); - recordJobMetrics(labels, JobStatus.FAILED, job); + if (job) { + recordJobMetrics(labels, JobStatus.FAILED, job); + } })); } else { diff --git a/src/index.ts b/src/index.ts index d1bfa0b..7e8429c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -114,11 +114,15 @@ export function init(opts: Options) { if (useGlobal) { queue.on('global:completed', async (jobId: number) => { const job = await queue.getJob(jobId); - recordJobMetrics(labels, JobStatus.COMPLETED, job); + if (job) { + recordJobMetrics(labels, JobStatus.COMPLETED, job); + } }); queue.on('global:failed', async (jobId: number) => { const job = await queue.getJob(jobId); - recordJobMetrics(labels, JobStatus.FAILED, job) + if (job) { + recordJobMetrics(labels, JobStatus.FAILED, job) + } }) } else { queue.on('completed', (job) => {