OptimalBits / bull

Premium Queue package for handling distributed jobs and messages in NodeJS.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Stuck should not be separate from JobStatus

jdforsythe opened this issue · comments

This JobStatus | 'stuck' requires us to use that in our codebase.

https://github.com/OptimalBits/bull/blame/60fa88f08637f0325639988a3f054880a04ce402/index.d.ts#L261

const stateProms: Promise<JobStatus | 'stuck'>[] = jobs.map((j) => j.getState());

However, 'stuck' is one of the valid job statuses, according to the docs and code, so why isn't it just a part of the JobStatus union?

https://github.com/OptimalBits/bull/blob/develop/index.d.ts#L358-L371

Then our code can be simplified:

const stateProms: Promise<JobStatus>[] = jobs.map((j) => j.getState());

There is no such thing as "stuck" status in Bull. When a job stalls, it goes back to wait, it cannot be in any other state other than the ones provided by the typescript definition.

@manast

The Reference says otherwise:

https://github.com/OptimalBits/bull/blob/develop/REFERENCE.md#jobgetstate

As does the presence of this function:

https://github.com/OptimalBits/bull/blob/develop/lib/job.js#L425-L429

As well as the getState() function:

https://github.com/OptimalBits/bull/blob/develop/lib/job.js#L435-L459

And this comment from the job tests:

bull/test/test_job.js

Lines 267 to 268 in 60fa88f

// This check is a bit of a hack. A job that is not found in any list will return the state
// stuck.

"A job that is not found in any list will return the state stuck"

And in any case, if 'stuck' wasn't a valid status, it should be removed from the types, not ignored.

https://github.com/OptimalBits/bull/blob/develop/index.d.ts#L250-L261

We cannot use JobStatus as the return type from getState():

Screenshot 2024-04-18 at 9 10 55 AM

We must use a union with 'stuck' every time to remove the type error:

Screenshot 2024-04-18 at 9 11 20 AM

I think some guy contributed to that and got merged somehow. It is not a state as far as I am concerned. Why do you need to care about this?

@manast because we have to keep adding it to our code to get the typing correct. We'd be fine if it were removed completely. We don't care about stuck but we're forced to add it to the type every time we get a job state.

I'd be happy to submit a PR to remove it, but what should getState() return if it's not in any of the lists?

A job must be in some list otherwise it would be a bug in bull, or the job has been removed and is not in the queue at all anymore.

@manast I submitted a PR to remove "stuck":

#2725