Skip to content

Commit

Permalink
fix(scripts): use command name in error message when moving to finish…
Browse files Browse the repository at this point in the history
…ed (#2483)
  • Loading branch information
roggervalf authored Mar 22, 2024
1 parent ea973b9 commit 3c335d4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/classes/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 || '{}');

Expand Down Expand Up @@ -687,7 +691,7 @@ export class Job<
delay,
);
(<any>multi).moveToDelayed(args);
command = 'delayed';
command = 'moveToDelayed';
} else {
// Retry immediately
(<any>multi).retryJob(
Expand All @@ -710,7 +714,7 @@ export class Job<
);
(<any>multi).moveToFinished(args);
finishedOn = args[this.scripts.moveToFinishedKeys.length + 1] as number;
command = 'failed';
command = 'moveToFinished';
}

const results = await multi.exec();
Expand Down
6 changes: 5 additions & 1 deletion src/classes/queue-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand All @@ -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,
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/test_job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>((resolve, reject) => {
worker.once('error', error => {
try {
Expand Down Expand Up @@ -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<void>((resolve, reject) => {
worker.once('error', error => {
try {
Expand Down

0 comments on commit 3c335d4

Please sign in to comment.