I'm using mongoose and Kue for the Flow control. I pass an object retrieved from the database to Kue. When the job get processed, the object hasn't anymore some functions, like .save() & others.
jobs.process('process', 5, function(job, done) {
var url = job.data.url;
var objo = job.data.comp;
request({uri:url, json:true}, function(err, res, body) {
objo.meta = body;
// Here it throw an error that save is note defined
// TypeError: Object #<Object> has no method 'save'
objo.save(function(err) {
if (err)
throw err;
console.log('Saved data for ' + objo.title);
done();
});
});
});
var q = db.Entity.find({}).sort('_id', 1).limit(10);
q.execFind(function(err, docs) {
docs.forEach(function(objo) {
jobs.create('process', {
comp : objo,
url : 'http://example.com/' + encodeURIComponent(objo.permalink) + '.js'
}).save();
})
});
Thanks in advance
This is because the Kue doesn't save the object entirely, it just saves the value of calling JSON.stringify()
on it. You'll need to pass the id of the object in, and grab the mongoose representation back out of the database in your worker.