From 3c335d49ba637145648c1ef0864d8e0d297dd890 Mon Sep 17 00:00:00 2001 From: Rogger Valverde Date: Thu, 21 Mar 2024 22:26:58 -0600 Subject: [PATCH] fix(scripts): use command name in error message when moving to finished (#2483) --- src/classes/job.ts | 10 +++++++--- src/classes/queue-base.ts | 6 +++++- tests/test_job.ts | 2 +- tests/test_worker.ts | 4 ++-- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/classes/job.ts b/src/classes/job.ts index 2b2ee0c12f..965aa8c79a 100644 --- a/src/classes/job.ts +++ b/src/classes/job.ts @@ -200,7 +200,7 @@ export class Job< : undefined; this.toKey = queue.toKey.bind(queue); - this.scripts = new Scripts(queue); + this.setScripts(); this.queueQualifiedName = queue.qualifiedName; } @@ -349,6 +349,10 @@ export class Job< return job; } + protected setScripts() { + this.scripts = new Scripts(this.queue); + } + private static optsFromJSON(rawOpts?: string): JobsOptions { const opts = JSON.parse(rawOpts || '{}'); @@ -687,7 +691,7 @@ export class Job< delay, ); (multi).moveToDelayed(args); - command = 'delayed'; + command = 'moveToDelayed'; } else { // Retry immediately (multi).retryJob( @@ -710,7 +714,7 @@ export class Job< ); (multi).moveToFinished(args); finishedOn = args[this.scripts.moveToFinishedKeys.length + 1] as number; - command = 'failed'; + command = 'moveToFinished'; } const results = await multi.exec(); diff --git a/src/classes/queue-base.ts b/src/classes/queue-base.ts index d61d4c3f92..a22cf424ac 100644 --- a/src/classes/queue-base.ts +++ b/src/classes/queue-base.ts @@ -71,7 +71,7 @@ export class QueueBase extends EventEmitter implements MinimalQueue { this.qualifiedName = queueKeys.getQueueQualifiedName(name); this.keys = queueKeys.getKeys(name); this.toKey = (type: string) => queueKeys.toKey(name, type); - this.scripts = new Scripts(this); + this.setScripts(); } /** @@ -81,6 +81,10 @@ export class QueueBase extends EventEmitter implements MinimalQueue { return this.connection.client; } + protected setScripts() { + this.scripts = new Scripts(this); + } + /** * Returns the version of the Redis instance the client is connected to, */ diff --git a/tests/test_job.ts b/tests/test_job.ts index 68d3e2ff86..6385213790 100644 --- a/tests/test_job.ts +++ b/tests/test_job.ts @@ -734,7 +734,7 @@ describe('Job', function () { await expect( job.moveToFailed(new Error('test error'), '0'), - ).to.be.rejectedWith(`Missing key for job ${job.id}. failed`); + ).to.be.rejectedWith(`Missing key for job ${job.id}. moveToFinished`); const processed = await client.hgetall( `${prefix}:${queueName}:${job.id}`, diff --git a/tests/test_worker.ts b/tests/test_worker.ts index 8448985455..7d52ef9405 100644 --- a/tests/test_worker.ts +++ b/tests/test_worker.ts @@ -1813,7 +1813,7 @@ describe('workers', function () { const job = await queue.add('test', { bar: 'baz' }); - const errorMessage = `Missing lock for job ${job.id}. failed`; + const errorMessage = `Missing lock for job ${job.id}. moveToFinished`; const workerError = new Promise((resolve, reject) => { worker.once('error', error => { try { @@ -1853,7 +1853,7 @@ describe('workers', function () { const job = await queue.add('test', { bar: 'baz' }); - const errorMessage = `Lock mismatch for job ${job.id}. Cmd failed from active`; + const errorMessage = `Lock mismatch for job ${job.id}. Cmd moveToFinished from active`; const workerError = new Promise((resolve, reject) => { worker.once('error', error => { try {