-
Notifications
You must be signed in to change notification settings - Fork 405
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
perf(worker): fetch next job on failure #2342
Conversation
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.
This is a small but a breaking change 😅
src/classes/worker.ts
Outdated
this.emit('failed', job, err, 'active'); | ||
|
||
if (failed) { | ||
const [jobData, jobId, limitUntil, delayUntil] = failed || []; |
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.
|| [] is redundant as it is already checking if failed is truthy
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.
done
src/classes/worker.ts
Outdated
@@ -766,8 +766,14 @@ will never work with more accuracy than 1ms. */ | |||
return; | |||
} | |||
|
|||
await job.moveToFailed(err, token); | |||
const failed = await job.moveToFailed(err, token, true); |
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 think "failed" here is misleading, as this includes the next job to process. Should be called probably "result" or similar.
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.
sounds good to me
src/classes/worker.ts
Outdated
@@ -786,7 +792,7 @@ will never work with more accuracy than 1ms. */ | |||
const result = await this.callProcessJob(job, token); | |||
return await handleCompleted(result); | |||
} catch (err) { | |||
return handleFailed(<Error>err); | |||
return await handleFailed(<Error>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.
await here will imply an unhandled exception if handleFailed throws an exception, is this the intent?
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.
it was placed when testing, removing it now
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.
LGTM. I see this PR more from a consistency side, as failed jobs are a deviation of the normal functioning of the queue and therefore it is not so important to optimize for this path, however having the same code for both completed and failed jobs is beneficial in my opinion.
## [5.10.2](v5.10.1...v5.10.2) (2024-07-19) ### Performance Improvements * **worker:** fetch next job on failure ([#2342](#2342)) ([f917b80](f917b80))
@@ -634,7 +634,7 @@ export class Job< | |||
err: E, | |||
token: string, | |||
fetchNext = false, | |||
): Promise<void> { | |||
): Promise<void | any[]> { |
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.
👀 The @returns
comment still says only void
is returned.
No description provided.