1

I am using express, and want to create a job anytime someone posts to my route. I would like the response to contain the job.id. However, the job id only populates in the callback of my queue.createFunction, so I am not quite sure how to return the job id? One solution I can think of is issuing a post request in my route to create a job, as their api returns an id as a response, but this seems inefficient.

swagbag
  • 105
  • 1
  • 9

1 Answers1

0

Not 100% if this answers your question but I've used the below to create a job on a POST request before:

const queue = kue.createQueue({
  redis: {
    port: conf.redis_port,
    host: conf.redis_host,
  },
})

app.post('endpoint', function(req, res, next) {
    let job = queue.create('some_action', req.data)

    // ... add job listeners etc.

    job.save(function(err) {
        if (err) {
            return res.send({ error: err })
        } else {
            return res.send({ id: job.id })
        }
    })

})

Hope it helps! :)