Skip to content

Commit

Permalink
fix: remove stuck as a job state
Browse files Browse the repository at this point in the history
  • Loading branch information
jdforsythe committed Apr 19, 2024
1 parent 60fa88f commit ed3cbcc
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 28 deletions.
2 changes: 1 addition & 1 deletion REFERENCE.md
Expand Up @@ -927,7 +927,7 @@ Adds a log row to this job specific job. Logs can be retrieved using [Queue#getJ
getState(): Promise
```

Returns a promise resolving to the current job's status (completed, failed, delayed etc.). Possible returns are: completed, failed, delayed, active, waiting, paused, stuck or null.
Returns a promise resolving to the current job's status (completed, failed, delayed etc.). Possible returns are: completed, failed, delayed, active, waiting, paused, or null.

Please take note that the implementation of this method is not very efficient, nor is it atomic. If your queue does have a very large quantity of jobs, you may want to avoid using this method.

Expand Down
6 changes: 1 addition & 5 deletions index.d.ts
Expand Up @@ -247,18 +247,14 @@ declare namespace Bull {
*/
isPaused(): Promise<boolean>;

/**
* Returns a promise resolving to a boolean which, if true, current job's state is stuck
*/
isStuck(): Promise<boolean>;

/**
* Returns a promise resolving to the current job's status.
* Please take note that the implementation of this method is not very efficient, nor is
* it atomic. If your queue does have a very large quantity of jobs, you may want to
* avoid using this method.
*/
getState(): Promise<JobStatus | 'stuck'>;
getState(): Promise<JobStatus>;

/**
* Update a specific job's data. Promise resolves when the job has been updated.
Expand Down
11 changes: 1 addition & 10 deletions lib/job.js
Expand Up @@ -422,12 +422,6 @@ Job.prototype.isPaused = function() {
return this._isInList('paused');
};

Job.prototype.isStuck = function() {
return this.getState().then(state => {
return state === 'stuck';
});
};

Job.prototype.isDiscarded = function() {
return this._discarded;
};
Expand All @@ -452,10 +446,7 @@ Job.prototype.getState = function() {
return result ? fn.state : null;
});
});
}, Promise.resolve())
.then(result => {
return result ? result : 'stuck';
});
}, Promise.resolve());
};

Job.prototype.remove = function() {
Expand Down
13 changes: 1 addition & 12 deletions test/test_job.js
Expand Up @@ -262,11 +262,6 @@ describe('Job', () => {
.then(stored => {
expect(stored).to.be(null);
return job.getState();
})
.then(state => {
// This check is a bit of a hack. A job that is not found in any list will return the state
// stuck.
expect(state).to.equal('stuck');
});
});
});
Expand Down Expand Up @@ -841,11 +836,6 @@ describe('Job', () => {
return Job.create(queue, { foo: 'baz' })
.then(job => {
return job
.isStuck()
.then(isStuck => {
expect(isStuck).to.be(false);
return job.getState();
})
.then(state => {
expect(state).to.be('waiting');
return scripts.moveToActive(queue).then(() => {
Expand Down Expand Up @@ -895,8 +885,7 @@ describe('Job', () => {
expect(res).to.be(1);
return job.getState();
})
.then(state => {
expect(state).to.be('stuck');
.then(() => {
return client.rpop(queue.toKey('wait'));
})
.then(() => {
Expand Down

0 comments on commit ed3cbcc

Please sign in to comment.