Skip to content

Commit

Permalink
refactor(error-codes): add error-codes enum (#716)
Browse files Browse the repository at this point in the history
  • Loading branch information
roggervalf authored Aug 31, 2021
1 parent df27ae9 commit 3070102
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
24 changes: 18 additions & 6 deletions src/classes/scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
QueueSchedulerOptions,
WorkerOptions,
} from '../interfaces';
import { ErrorCodes } from '../enums';
import { array2obj, getParentKey } from '../utils';
import { Worker } from './worker';
import { QueueScheduler } from './queue-scheduler';
Expand Down Expand Up @@ -242,15 +243,15 @@ export class Scripts {
state: string,
): Error {
switch (code) {
case -1:
case ErrorCodes.JobNotExist:
return new Error(`Missing key for job ${jobId}. ${command}`);
case -2:
case ErrorCodes.JobLockNotExist:
return new Error(`Missing lock for job ${jobId}. ${command}`);
case -3:
case ErrorCodes.JobNotInState:
return new Error(
`Job ${jobId} is not in the ${state} state. ${command}`,
);
case -4:
case ErrorCodes.JobPendingDependencies:
return new Error(`Job ${jobId} has pending dependencies. ${command}`);
}
}
Expand Down Expand Up @@ -425,7 +426,7 @@ export class Scripts {
queue: MinimalQueue,
jobId: string,
timestamp: number,
) {
): Promise<void> {
const client = await queue.client;

const args = this.moveToDelayedArgs(queue, jobId, timestamp);
Expand All @@ -435,6 +436,17 @@ export class Scripts {
}
}

/**
* Move parent job to waiting-children state.
*
* @returns true if job is successfully moved, false if there are pending dependencies.
* @throws JobNotExist
* This exception is thrown if jobId is missing.
* @throws JobLockNotExist
* This exception is thrown if job lock is missing.
* @throws JobNotInState
* This exception is thrown if job is not in active state.
*/
static async moveToWaitingChildren(
queue: MinimalQueue,
jobId: string,
Expand Down Expand Up @@ -497,7 +509,7 @@ export class Scripts {
/**
* Attempts to reprocess a job
*
* @param {Job} job
* @param job -
* @param {Object} options
* @param {String} options.state The expected job state. If the job is not found
* on the provided state, then it's not reprocessed. Supported states: 'failed', 'completed'
Expand Down
6 changes: 6 additions & 0 deletions src/enums/error-codes.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export enum ErrorCodes {
JobNotExist = -1,
JobLockNotExist = -2,
JobNotInState = -3,
JobPendingDependencies = -4,
}
3 changes: 2 additions & 1 deletion src/enums/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './retry-errors.enum';
export * from './retry-errors.enum';
export * from './error-codes.enum';

0 comments on commit 3070102

Please sign in to comment.