I have an API endpoint that serves some JSON from a MongoDB. Simply like so:
router.get('/api/links', function (req, res) {
// Find existing links
links.find({ feed: 1 }, function (err, links) {
res.json(links)
})
})
I would like this endpoint to trigger a Kue job, and when this job is finished, I would like to somehow push the result of the job (new links in the database) to the client – something like the Twitter stream API, which keeps an open HTTP GET
request.
router.get('/api/links', function (req, res) {
// Find existing links
links.find({ feed: 1 }, function (err, links) {
res.json(links)
})
// Kue job to update the links database
jobs.create('update subscriptions', {
title: req.user.username,
feeds: feeds
}).save()
// When the job is done, the new links in the database (the output
// of the Kue job) should be pushed to the client
})
I'm not sure, however, how to get the result of the Kue job, nor how I should push this newly received data to the client when the job is done.
If there is no way to get the result of a Kue job, I could just query the database for new documents. However, I'm still not sure how to send another response to the client. Hoping someone could point me in the right direction!