Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@gtanner/farm

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gtanner/farm - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

lib/conf.js

14

examples/hello.js

@@ -17,9 +17,11 @@ var farm = require('../lib/farm'),

farm.jobs.send('hello', function (err, world) {
farm.jobs.distribute(['?', '?', '?'], function (err, excited) {
console.log('hello', world, excited.join(''));
broker.stop();
process.exit();
setTimeout(function () {
farm.jobs.send('hello', function (err, world) {
farm.jobs.distribute(['?', '?', '?'], function (err, excited) {
console.log('hello', world, excited.join(''));
broker.stop();
process.exit();
});
});
});
}, 500);
}

@@ -26,0 +28,0 @@ else {

@@ -16,2 +16,3 @@ var farm = require('../lib/farm'),

farm.events.subscribe('stats', console.log);
async.forever(function (callback) {

@@ -29,2 +30,3 @@ farm.jobs.distribute(['ping', 'ping', 'ping', 'ping'], function (err, result) {

else {
var pings = 0;
// setup a worker callback function

@@ -34,2 +36,3 @@ farm.worker(function (task, callback) {

case 'ping':
pings++;
setTimeout(async.apply(callback, null, process.pid + ':pong'), 1000);

@@ -41,4 +44,8 @@ break;

setInterval(function () {
farm.events.publish('stats', { pid: process.pid, pings: pings });
}, 5000);
//connect to localhost and designate we are a worker
farm.join('localhost', {worker: true});
}

@@ -19,17 +19,19 @@ //This example shows that a worker can

async.parallel([
async.apply(farm.jobs.send, 'hello'),
async.apply(farm.jobs.distribute, ['hello','hello','hello']),
async.apply(farm.jobs.distribute, ['hello','hello','hello'])
], function (err) {
broker.stop();
// Not expecting an error
if (err) {
console.log(err.stack);
process.exit(1);
}
setTimeout(function () {
async.series([
async.apply(farm.jobs.send, 'hello'),
async.apply(farm.jobs.distribute, ['hello','hello','hello']),
async.apply(farm.jobs.distribute, ['hello','hello','hello'])
], function (err) {
broker.stop();
// Not expecting an error
if (err) {
console.log(err.stack);
process.exit(1);
}
console.log("all good!");
process.exit();
});
console.log("all good!");
process.exit();
});
}, 500);
}

@@ -36,0 +38,0 @@ else {

@@ -0,4 +1,5 @@

var conf = require('./conf');
module.exports = {
start: function (cfg) {
cfg = cfg || { reaper: {} };
cfg = cfg || {};
var fork = require('child_process').fork,

@@ -5,0 +6,0 @@ reqrep = fork(require.resolve('./broker/reqrep')),

var zmq = require('zmq');
var conf = require('../conf');
module.exports = {
start: function () {
start: function (cfg) {
cfg = conf.broker(cfg);
var xsub = zmq.socket('xsub'),

@@ -9,4 +11,4 @@ xpub = zmq.socket('xpub'),

xpub.bindSync('tcp://*:5555');
xsub.bindSync('tcp://*:5556');
xpub.bindSync('tcp://*:' + cfg.get('ports.subscribe'));
xsub.bindSync('tcp://*:' + cfg.get('ports.publish'));

@@ -13,0 +15,0 @@ xsub.on('message', function(data) { xpub.send(data); });

@@ -5,2 +5,3 @@ var zmq = require('zmq'),

utils = require('../utils'),
conf = require('../conf'),
tasks = {};

@@ -10,2 +11,3 @@

start: function (cfg) {
cfg = conf.broker(cfg);
var router = zmq.socket('router'),

@@ -35,6 +37,6 @@ push = zmq.socket('push'),

//Don't fear the reaper
if (cfg.reaper.interval) {
if (cfg.get('reaper.interval')) {
setInterval(function () {
var keys = Object.keys(tasks);
if (cfg.reaper.log && keys.length) {
if (cfg.get('reaper.log') && keys.length) {
console.log(keys.length);

@@ -45,3 +47,3 @@ }

task.ping = task.ping || Date.now();
if ((Date.now() - task.ping) > cfg.reaper.limit) {
if ((Date.now() - task.ping) > cfg.get('reaper.limit')) {
task.ping = Date.now();

@@ -52,3 +54,3 @@ console.log('reaping', key, 'at', task.ping);

});
}, cfg.reaper.interval);
}, cfg.get('reaper.interval'));
}

@@ -75,3 +77,3 @@

push.send([id, task.task]);
}, cfg.retryTimeout || 100);
}, cfg.get('retryTimeout'));
return;

@@ -89,5 +91,5 @@ default:

router.bindSync('tcp://*:5003');
push.bindSync('tcp://*:5557');
pull.bindSync('tcp://*:5558');
router.bindSync('tcp://*:' + cfg.get('ports.distribute'));
push.bindSync('tcp://*:' + cfg.get('ports.task'));
pull.bindSync('tcp://*:' + cfg.get('ports.result')) ;

@@ -97,5 +99,5 @@ setInterval(function () {

// but seems to get things working
pull._flush();
push._flush();
router._flush();
pull.resume();
push.resume();
router.resume();
}, 1000);

@@ -102,0 +104,0 @@

var zmq = require('zmq');
var conf = require('../conf');
module.exports = {
start: function () {
start: function (cfg) {
cfg = conf.broker(cfg);
var frontend = zmq.socket('router'),

@@ -9,4 +11,4 @@ backend = zmq.socket('dealer'),

frontend.bindSync('tcp://*:5000');
backend.bindSync('tcp://*:5001');
frontend.bindSync('tcp://*:' + cfg.get('ports.send'));
backend.bindSync('tcp://*:' + cfg.get('ports.worker'));

@@ -13,0 +15,0 @@ frontend.on('message', function () {

@@ -26,4 +26,4 @@ var zmq = require('zmq'),

join: function (ip, cfg) {
sub.connect('tcp://' + ip + ':' + 5555);
pub.connect('tcp://' + ip + ':' + 5556);
sub.connect('tcp://' + ip + ':' + cfg.get('ports.subscribe'));
pub.connect('tcp://' + ip + ':' + cfg.get('ports.publish'));
},

@@ -30,0 +30,0 @@ close: function () {

@@ -48,8 +48,8 @@ var zmq = require('zmq'),

join: function (ip, cfg) {
distributer.connect('tcp://' + ip + ':5003');
distributer.connect('tcp://' + ip + ':' + cfg.get('ports.distribute'));
pingInterval = cfg.ping || pingInterval || 1000;
if (cfg.worker) {
pull.connect('tcp://' + ip + ':5557');
push.connect('tcp://' + ip + ':5558');
if (cfg.get('worker')) {
pull.connect('tcp://' + ip + ':' + cfg.get('ports.task'));
push.connect('tcp://' + ip + ':' + cfg.get('ports.result'));
}

@@ -56,0 +56,0 @@ },

@@ -60,5 +60,5 @@ var zmq = require('zmq'),

join: function (ip, cfg) {
req.connect('tcp://' + ip + ':5000');
if (cfg.worker) {
rep.connect('tcp://' + ip + ':5001');
req.connect('tcp://' + ip + ':' + cfg.get('ports.send'));
if (cfg.get('worker')) {
rep.connect('tcp://' + ip + ':' + cfg.get('ports.worker'));
}

@@ -65,0 +65,0 @@

var pubsub = require('./client/pubsub'),
reqrep = require('./client/reqrep'),
conf = require('./conf'),
initialized = false,

@@ -14,3 +15,3 @@ pushpull = require('./client/pushpull');

join: function (ip, cfg) {
cfg = cfg || {};
cfg = conf.client(cfg);
initialized = initialized ? true : module.exports.init();

@@ -17,0 +18,0 @@ pubsub.join(ip, cfg);

{
"name": "@gtanner/farm",
"version": "1.0.0",
"version": "2.0.0",
"description": "Distributed computing orchestration platform",

@@ -17,3 +17,4 @@ "homepage": "https://github.com/bithound/farm.bithound.io",

"async": "^1.4.2",
"uuid": "2.0.1",
"convict": "^1.3.0",
"uuid": "^2.0.2",
"zmq": "^2.13.0"

@@ -20,0 +21,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc