Skip to content
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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Conversation

roggervalf
Copy link
Collaborator

@roggervalf roggervalf commented Feb 3, 2023

ref #301

@@ -139,6 +139,8 @@ export interface WorkerListener<

const RATE_LIMIT_ERROR = 'bullmq:rateLimitExceeded';

const DISCARD_TTL_ERROR = 'bullmq:discardTtlExceeded';
Copy link
Contributor

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.

@@ -669,6 +670,12 @@ export class Worker<
lockExtender();
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

@@ -669,6 +670,12 @@ export class Worker<
lockExtender();

try {
if (this.opts.discardTtl) {
if (this.opts.discardTtl < Date.now() - job.timestamp) {
return handleFailed(new Error(DISCARD_TTL_ERROR));
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

@roggervalf roggervalf requested a review from manast April 14, 2023 00:36
@valeeum
Copy link

valeeum commented Aug 11, 2023

Hi team! Are there any plans to merge this functionality?

Copy link
Contributor

@manast manast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@manast manast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunatelly I think this functionality cannot be implemented after the job has been fetched from the queue, as it will affect rate limiting. So it should instead be moved to moveToActive, where it can be discarded before it affects the rate limiter. Also it will allow for discarding several jobs in one go, cannot be too many though or it will keep Redis busy for too long.

@@ -649,7 +651,7 @@ export class Worker<

if (
err instanceof DelayedError ||
err.name == 'DelayedError' ||
err.message == 'DelayedError' ||
err instanceof WaitingChildrenError ||
err.name == 'WaitingChildrenError'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about this err.name no need to also change to message ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants