I’m sending a task to a worker on a different url using this format:
Workers = function (workers) {
var self = this;
this.workers = [];
workers.forEach(function (url) {
var worker = DDP.connect(url);
Tracker.autorun(function () {
var status = worker.status();
if (status.connected) {
console.log("worker connected: " + url);
self.workers.push(worker);
} else {
var index = self.workers.indexOf(worker);
if (index >= 0) {
console.log("worker disconnected: " + url);
self.workers.splice(index, 1);
}
}
});
});
this._nextWorker = 0;
}
var workers = new Workers(process.env.WORKER_URLS.split(';'));
Meteor.methods({
cj: function(task) {
this.unblock();
return workers.cj(task);
},
If I send a really long task, however, the worker disconnects. As soon as the task has finished on the worker, the worker reconnects, and the main app tries to send the task again. It gets stuck in infinite loops.
I’ve tried every combination of unblock and defer I can think of! Can I stop the worker from being disconnected? Or do I have to alter the behaviour of the workers in some way?
Thanks!