我目前正在爲我自己的項目需要處理的東西在後臺,但是,我需要溝通Express和Kue。 但是,有關當前設置的更多信息: 我的Express.js佔用了主機內部一半以上的CPU。這按預期工作。現在我運行另一個運行kue.js進行後臺處理的節點進程。由於kue通過redis調度它的工作,我現在的主要問題是我如何能夠將數據從已處理的後臺作業發送回我的主要node.js應用程序。集羣與Express.js和Kue.js
我的設置短概要:
app.js(與節點app.js運行)
var cluster = require('cluster'), Datasets = require('./models/datasets'), kue = require('kue'), jobs = cue.createQueue();
if(cluster.isMaster) {
// Forking going on here
} else {
// Express.js app runs here
app.get('/', function(req, res) {
// Now here is where i schedule the job and i would like to retrieve an answer from the job when its done, like with on('complete', ...) but that doesn't work at all
jobs.create('stuff', {lorem: 'ipsum', dolor: ''}).save();
});
}
background.js(與節點background.js同時運行,這是不一樣的節點過程像應用程序)
// omiting libraries right now, its simply kue and datasets like in app.'s
jobs.process('stuff', function(job, done){
//processing some background stuff here
// Now here i would like to pass back an array of objects to the app.js process after the job is completed.
});
任何人都有這樣的想法?每一個幫助表示讚賞。
誠懇, 克里斯賓