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

Job.fromId String Parameter Contradicts Method Comment/Implementation #134

Open
bobdercole opened this issue Feb 11, 2020 · 1 comment
Open

Comments

@bobdercole
Copy link
Contributor

bobdercole commented Feb 11, 2020

The jobId parameter in the following method accepts string. However, the comment in the method states that it could be undefined. The conditional then proceeds to check for a truthy value.

bullmq/src/classes/job.ts

Lines 138 to 145 in 36726bf

static async fromId(queue: QueueBase, jobId: string) {
// jobId can be undefined if moveJob returns undefined
if (jobId) {
const client = await queue.client;
const jobData = await client.hgetall(queue.toKey(jobId));
return isEmpty(jobData) ? null : Job.fromJSON(queue, jobData, jobId);
}
}

This was brought up while trying to fix the return type of the method in #133. I believe we came to the conclusion to remove the conditional check.

We would also need to review any code that consumes Job.fromId to ensure undefined isn't being passed from anywhere. These could be easily found by switching strictNullChecks to true. I believe this was brought up in GH-112.

"strictNullChecks": false,

An alternative is to simply change the parameter to jobId?: string. However, I feel like it's weird to have an optional ID parameter on a method named fromId.

I could make a PR once a merge decision is made for PR #133, since the code is sort of intertwined.

References:
#133 (comment)
#130 (comment)

@manast
Copy link
Contributor

manast commented Feb 11, 2020

I agree that a method that does nothing if you do not provide the second parameter is very awkward. These are remains from older code, thats why it looks like this. So best is to keep it mandatory, but as you wrote we need to make sure that all the calls to this method always pass a defined jobId.

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

No branches or pull requests

2 participants