MongoDB から JSON を提供する API エンドポイントがあります。単純に次のように:
router.get('/api/links', function (req, res) {
// Find existing links
links.find({ feed: 1 }, function (err, links) {
res.json(links)
})
})
このエンドポイントで Kue ジョブをトリガーし、このジョブが終了したら、何らかの形でジョブの結果 (データベース内の新しいリンク) をクライアントにプッシュしたいと考えています。 HTTPGET
リクエストを開きます。
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
})
ただし、Kue ジョブの結果を取得する方法も、ジョブが完了したときにこの新しく受信したデータをクライアントにプッシュする方法もわかりません。
Kue ジョブの結果を取得する方法がない場合は、データベースにクエリを実行して新しいドキュメントを探すことができます。ただし、クライアントに別の応答を送信する方法はまだわかりません。誰かが私を正しい方向に向けてくれることを願っています!