Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return task;
};
self.addTask = function(task){
self.taskPool.add(task);
};
self.getTask = function(task_id){
return self.taskPool.get(task_id);
};
var context = require("zeromq");
self.id = robust.util.makeUUID({prefix:"client"});
self.results_socket = context.createSocket("pull");
self.code_socket = context.createSocket("push");
self.results_socket.on("message", function(data){
if (data == robust.constants.HANDSHAKE) {
// do nothing
return true;
} else if (data == robust.constants.READY) {
console.log("Ready handshake");
self.emit("ready");
return true;
} else {
// TODO: need safe JSON parsing
data = JSON.parse(data);
robust.util.info("Receiving results for task " + data['task_id']);
console.log(data);
}
};
self.addTask = function(task){
self.taskPool.add(task);
};
self.getTask = function(task_id){
return self.taskPool.get(task_id);
};
var context = require("zeromq");
self.id = robust.util.makeUUID({prefix:"client"});
self.results_socket = context.createSocket("pull");
self.code_socket = context.createSocket("push");
self.results_socket.on("message", function(data){
if (data == robust.constants.HANDSHAKE) {
// do nothing
return true;
} else if (data == robust.constants.READY) {
console.log("Ready handshake");
self.emit("ready");
return true;
} else {
// TODO: need safe JSON parsing
data = JSON.parse(data);
robust.util.info("Receiving results for task " + data['task_id']);
console.log(data);
}
if (typeof(options.crankshaft) != "undefined") {
crankshaft_endpoint = options.crankshaft;
}
}
self.cylinder_block = context.createSocket("push");
self.cylinder_block.bind(cylinder_block_endpoint, function(err){
if (err) {
throw err;
}
self.emit("cylinder block ready");
self.checkoff("cylinder block", self.handleCheckoff);
});
self.crankshaft = context.createSocket("pull");
self.crankshaft.bind(crankshaft_endpoint, function(err){
if (err) {
throw err;
}
self.emit("crankshaft ready");
self.checkoff("crankshaft", self.handleCheckoff);
});
self.crankshaft.on("message", function(data){
var parsed_data = JSON.parse(data);
var task = self.getRunningTask(parsed_data.running_task_id);
//if (task && task.getCallback()) {
// task.getCallback().call(null, data);
//}
#!/usr/bin/env node
'use strict';
var ZMQ = require('zeromq');
var BROKER_REP = '127.0.0.1:5554';
var BROKER_PUB = '127.0.0.1:5555';
function log() {}
//var log = console.log;
//
// broker
//
var brokerListener = ZMQ.createSocket('sub');
var brokerPublisher = ZMQ.createSocket('pub');
var n = 0;
brokerListener.bind('tcp://' + BROKER_REP, function(err) {
if (err) throw err;
brokerListener.subscribe('');
brokerListener.on('message', function(data) {
log('BIN: ' + data.toString('utf8'));
var r = brokerPublisher.send(data);
if (r) {
n++;
console.error('PUB FAILED: ', r, n);
}
});
console.error('Broker is listening to ' + BROKER_REP + '...');
});
brokerPublisher.bind('tcp://' + BROKER_PUB, function(err) {
if (err) throw err;
#!/usr/bin/env node
'use strict';
var ZMQ = require('zeromq');
var BROKER_REP = '127.0.0.1:5554';
var BROKER_PUB = '127.0.0.1:5555';
function log() {}
var log = console.log;
//
// broker
//
var brokerListener = ZMQ.createSocket('rep');
var brokerPublisher = ZMQ.createSocket('pub');
var n = 0;
brokerListener.bind('tcp://' + BROKER_REP, function(err) {
if (err) throw err;
brokerListener.on('message', function(data) {
if (!(n % 10000)) console.error('BIN', n, Date.now());
++n;
log('BIN: ' + data.toString('utf8'));
brokerPublisher.send(data);
brokerListener.send('');
});
console.error('Broker is listening to ' + BROKER_REP + '...');
});
brokerPublisher.bind('tcp://' + BROKER_PUB, function(err) {
if (err) throw err;
brokerPublisher.on('message', function(data) {
]);
var cylinder_block_endpoint = defaults.cylinder_block;
var crankshaft_endpoint = defaults.crankshaft;
if (typeof(options) != "undefined") {
if (typeof(options.cylinder_block) != "undefined") {
cylinder_block_endpoint = options.cylinder_block;
}
if (typeof(options.crankshaft) != "undefined") {
crankshaft_endpoint = options.crankshaft;
}
}
self.cylinder_block = context.createSocket("push");
self.cylinder_block.bind(cylinder_block_endpoint, function(err){
if (err) {
throw err;
}
self.emit("cylinder block ready");
self.checkoff("cylinder block", self.handleCheckoff);
});
self.crankshaft = context.createSocket("pull");
self.crankshaft.bind(crankshaft_endpoint, function(err){
if (err) {
throw err;
}
self.emit("crankshaft ready");
engine.piston.server = function(){
var self = this;
self.started = false;
self.running = function(){
return self.started;
};
var context = require('zeromq');
self.code_responder = context.createSocket('rep');
self.code_responder.on('message', function(data) {
var response = engine.piston.fire(data);
self.code_responder.send(JSON.stringify(response));
return true;
});
self.start = function(endpoint, callback){
self.code_responder.bind(endpoint, function(err) {
if(err) {
console.log(err);
} else {
self.started = true;
if (typeof callback != "undefined") {
callback.call();
function Worker(id) {
var w = ZMQ.createSocket('req');
w.connect('tcp://' + BROKER_REP);
this.send = function(data) {
log('WOUT:', id, data.toString('utf8'));
return w.send(data);
};
var w1 = ZMQ.createSocket('sub');
w1.connect('tcp://' + BROKER_PUB);
w1.subscribe('');
var n = 0;
w1.on('message', function(data) {
if (!(n % 10000)) console.error('WIN', n, Date.now());
++n;
log('WIN:', id, data.toString('utf8'));
});
}
robust.worker = function(options){
var context = require('zeromq');
var self = this;
self.process_id = options.process_id;
self.code_receiver = context.createSocket("pull");
self.results_sender = context.createSocket("push");
self.code_receiver.connect("ipc://code.ipc");
self.results_sender.connect("ipc://results.ipc");
self.code_receiver.on("message", function(data){
if (data == robust.constants.HANDSHAKE) {
self.results_sender.send(robust.constants.READY);
return true;
}
var config = JSON.parse(data);
var code = config['code'];
var context = config['context'];
var locals = config['locals'];
var task_id = config['task_id'];
robust.worker = function(options){
var context = require('zeromq');
var self = this;
self.process_id = options.process_id;
self.code_receiver = context.createSocket("pull");
self.results_sender = context.createSocket("push");
self.code_receiver.connect("ipc://code.ipc");
self.results_sender.connect("ipc://results.ipc");
self.code_receiver.on("message", function(data){
if (data == robust.constants.HANDSHAKE) {
self.results_sender.send(robust.constants.READY);
return true;
}
var config = JSON.parse(data);
var code = config['code'];
var context = config['context'];
var locals = config['locals'];
var task_id = config['task_id'];