Skip to content

Commit

Permalink
fix: modified QueueGetters.getJob and Job.fromId to return undefined
Browse files Browse the repository at this point in the history
instead of null
  • Loading branch information
bobdercole committed Feb 11, 2020
1 parent 65183fc commit ede352b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/classes/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,15 @@ export class Job<T = any, R = any> {
return job;
}

static async fromId(queue: QueueBase, jobId: string): Promise<Job | null> {
static async fromId(
queue: QueueBase,
jobId: string,
): Promise<Job | undefined> {
// jobId can be undefined if moveJob returns undefined
if (jobId) {
const client = await queue.client;
const jobData = await client.hgetall(queue.toKey(jobId));
return isEmpty(jobData) ? null : Job.fromJSON(queue, jobData, jobId);
return isEmpty(jobData) ? undefined : Job.fromJSON(queue, jobData, jobId);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/classes/queue-getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Job } from './job';
import { clientCommandMessageReg } from './worker';

export class QueueGetters extends QueueBase {
getJob(jobId: string): Promise<Job | null> {
getJob(jobId: string): Promise<Job | undefined> {
return Job.fromId(this, jobId);
}

Expand Down

0 comments on commit ede352b

Please sign in to comment.