-
Notifications
You must be signed in to change notification settings - Fork 359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(worker): add discardTtl option #1653
base: master
Are you sure you want to change the base?
Changes from 1 commit
c3b7ba0
0c2df1f
68b87bd
96be83f
22554d3
74df17b
2121a64
c8b4edb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,6 +139,8 @@ export interface WorkerListener< | |
|
||
const RATE_LIMIT_ERROR = 'bullmq:rateLimitExceeded'; | ||
|
||
const DISCARD_TTL_ERROR = 'bullmq:discardTtlExceeded'; | ||
|
||
/** | ||
* | ||
* This class represents a worker that is able to process jobs from the queue. | ||
|
@@ -527,7 +529,6 @@ export class Worker< | |
? Math.ceil(blockTimeout) | ||
: blockTimeout; | ||
|
||
const now = Date.now(); | ||
const jobId = await client.brpoplpush( | ||
this.keys.wait, | ||
this.keys.active, | ||
|
@@ -669,6 +670,12 @@ export class Worker< | |
lockExtender(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, seems a bit counterintuitive that we need to extend the lock if we are going to fail the job, but I guess this is necessary to avoid the risk of not having a lock when handling the failed job, which requires a valid lock. |
||
|
||
try { | ||
if (this.opts.discardTtl) { | ||
if (this.opts.discardTtl < Date.now() - job.timestamp) { | ||
return handleFailed(new Error(DISCARD_TTL_ERROR)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something hit me about this. Are we really sure we want to fail the job here? I am thinking that discarded jobs would probably just pollute the failed set where there could be legitimate jobs that failed for some reason that needs to be debugged. Maybe it is better to just remove the job while sending an event for it. |
||
} | ||
} | ||
|
||
const result = await this.callProcessJob(job, token); | ||
return await handleCompleted(result); | ||
} catch (err) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we will need to replace this constants by an enum soon.