Automattic / Automattic/kue

trouble getting job id immediately after a save

Open
#1,177 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
9.4k
Forks
858
PR merge metrics
No merged PRs in 30d

Description

I have a simple node.js server. It supports the ocassional HTTP request to
myserver/goDoSomethingThatTakesAWhile

I want to kue the job and pass back the job Id in the HTTP response and then let the client go wild checking for progress.

My problem is that the function that does the save and and wants to return the ID completes before the save completes and I do not get the job Id to send to the client.

```
let job = this.queue.create(name,dj)
.save(function (err) {
if (!err) {
console.log(job.id); // ==> works as expected but the function has already completed
} else {
//TODO
}
});
//console.log(job.id); ==> undefined at this point ergo the problem;
//would like to return job.id at this point, but it is not defined.
```
I suspect I am missing something terribly obvious here.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at the queue.create(name, dj).save callback shown in the issue and trace how the surrounding HTTP handler sends its response. Verify when the job ID becomes available relative to save completion, then confirm that the handler can return that ID after a successful save and handles the error path.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.