Skip to content

Commit

Permalink
fix(worker): do not wait for slow jobs fixes #2290
Browse files Browse the repository at this point in the history
  • Loading branch information
manast committed Nov 23, 2023
1 parent f3f8491 commit 568d758
Show file tree
Hide file tree
Showing 2 changed files with 1,103 additions and 1,057 deletions.
11 changes: 7 additions & 4 deletions src/classes/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
DELAY_TIME_1,
isNotConnectionError,
isRedisInstance,
isRedisVersionLowerThan,
WORKER_SUFFIX,
} from '../utils';
import { QueueBase } from './queue-base';
Expand Down Expand Up @@ -442,12 +441,16 @@ export class Worker<
}
}

let job: Job<DataType, ResultType, NameType> | void;
// Since there can be undefined jobs in the queue (when a job fails or queue is empty)
// we iterate until we find a job.
while (!job && asyncFifoQueue.numTotal() > 0) {
let job: Job<DataType, ResultType, NameType> | void;
do {
job = await asyncFifoQueue.fetch();
}
} while (
!job &&
asyncFifoQueue.numTotal() > 0 &&
asyncFifoQueue.numQueued() > 0
);

if (job) {
const token = job.token;
Expand Down
Loading

0 comments on commit 568d758

Please sign in to comment.