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

fix: remove stuck as a job state #2725

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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