Skip to content

Commit

Permalink
fix: do not block if blockTime is zero
Browse files Browse the repository at this point in the history
  • Loading branch information
manast committed Sep 1, 2019
1 parent 9267541 commit 13b2df2
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/classes/queue-scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ export class QueueScheduler extends QueueBase {
this.run();
}

private async run() {
private async run(streamLastId = '0-0') {
const key = this.delayStreamKey();
let streamLastId = '0-0'; // TODO: updateDelaySet should also return the last event id

while (!this.closing) {
// Check if at least the min stalled check time has passed.
Expand All @@ -63,13 +62,18 @@ export class QueueScheduler extends QueueBase {
),
);

const data = await this.client.xread(
'BLOCK',
blockTime,
'STREAMS',
key,
streamLastId,
);
let data;
if (blockTime) {
data = await this.client.xread(
'BLOCK',
blockTime,
'STREAMS',
key,
streamLastId,
);
} else {
data = await this.client.xread('STREAMS', key, streamLastId);
}

if (data && data[0]) {
const stream = data[0];
Expand Down Expand Up @@ -118,7 +122,5 @@ export class QueueScheduler extends QueueBase {
stalled.forEach((jobId: string) => {
this.emit('stalled', jobId);
});

console.log({ failed, stalled });
}
}

0 comments on commit 13b2df2

Please sign in to comment.