-
Notifications
You must be signed in to change notification settings - Fork 391
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(scheduler): divide timestamp by 4096 in update set fixes #168
- Loading branch information
Showing
3 changed files
with
54 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,10 +48,11 @@ export class QueueScheduler extends QueueBase { | |
|
||
const key = this.keys.delay; | ||
const opts = this.opts as QueueSchedulerOptions; | ||
const delaySet = await this.updateDelaySet(Date.now()); | ||
|
||
const [nextTimestamp] = delaySet; | ||
let streamLastId = delaySet[1] || '0-0'; | ||
const [nextTimestamp, streamId = '0-0'] = await this.updateDelaySet( | ||
Date.now(), | ||
); | ||
let streamLastId = streamId; | ||
|
||
if (nextTimestamp) { | ||
this.nextTimestamp = nextTimestamp / 4096; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
manast
Author
Contributor
|
||
|
@@ -64,6 +65,7 @@ export class QueueScheduler extends QueueBase { | |
// Listen to the delay event stream from lastDelayStreamTimestamp | ||
// Can we use XGROUPS to reduce redundancy? | ||
const nextDelay = this.nextTimestamp - Date.now(); | ||
|
||
const blockTime = Math.round( | ||
Math.min(opts.stalledInterval, Math.max(nextDelay, 0)), | ||
); | ||
|
@@ -104,7 +106,7 @@ export class QueueScheduler extends QueueBase { | |
if (delay <= 0) { | ||
const [nextTimestamp, id] = await this.updateDelaySet(now); | ||
if (nextTimestamp) { | ||
this.nextTimestamp = nextTimestamp / 4096; | ||
this.nextTimestamp = nextTimestamp; | ||
streamLastId = id; | ||
} else { | ||
this.nextTimestamp = Number.MAX_VALUE; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Should we keep
/ 4096
here? WhileupdateDelaySet
already return it divided by 4096 in /updateDelaySet-7.lua So it looks like it divided by 4096 two times.PS. I think that 4096 logic should be kept only in Lua scripts. While this logic is placed in Lua and JS we will have such problems.