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

hive-dev

Package Overview
Dependencies
Maintainers
3
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hive-dev - npm Package Compare versions

Comparing version 1.0.14 to 1.0.15

161

example/app.js

@@ -28,115 +28,23 @@ /**

var hive = new Hive({}, [],[{
name: 'Weather',
provider: 'weather.com',
runs: 'getWeather', // any function on the global scope, even 'myObj.subObj.myFunc'
options: {
frequency: 'every 5 seconds',
priority: 'default',
// throttle is ignored if frequency is set --^
throttle: {
limit: 5, // how many tasks per 'provider' per limit time (per)
per: '10 seconds' // time limit
}
},
data: {
foo: 'bar'
}
},{
name: 'Weather',
provider: 'weather.com',
runs: 'getWeather', // any function on the global scope, even 'myObj.subObj.myFunc'
options: {
frequency: 'every 5 seconds',
priority: 'default',
// throttle is ignored if frequency is set --^
throttle: {
limit: 5, // how many tasks per 'provider' per limit time (per)
per: '10 seconds' // time limit
}
},
data: {
foo: 'bar'
}
},{
name: 'Weather',
provider: 'weather.com',
runs: 'getWeather', // any function on the global scope, even 'myObj.subObj.myFunc'
options: {
frequency: 'every 5 seconds',
priority: 'default',
// throttle is ignored if frequency is set --^
throttle: {
limit: 5, // how many tasks per 'provider' per limit time (per)
per: '10 seconds' // time limit
}
},
data: {
foo: 'bar'
}
},{
name: 'Weather',
provider: 'weather.com',
runs: 'getWeather', // any function on the global scope, even 'myObj.subObj.myFunc'
options: {
frequency: 'every 5 seconds',
priority: 'default',
// throttle is ignored if frequency is set --^
throttle: {
limit: 5, // how many tasks per 'provider' per limit time (per)
per: '10 seconds' // time limit
}
},
data: {
foo: 'bar'
}
},{
name: 'Weather',
provider: 'weather.com',
runs: 'getWeather', // any function on the global scope, even 'myObj.subObj.myFunc'
options: {
frequency: 'every 5 seconds',
priority: 'default',
// throttle is ignored if frequency is set --^
throttle: {
limit: 5, // how many tasks per 'provider' per limit time (per)
per: '10 seconds' // time limit
}
},
data: {
foo: 'bar'
}
},{
name: 'Weather',
provider: 'weather.com',
runs: 'getWeather', // any function on the global scope, even 'myObj.subObj.myFunc'
options: {
frequency: 'every 5 seconds',
priority: 'default',
// throttle is ignored if frequency is set --^
throttle: {
limit: 5, // how many tasks per 'provider' per limit time (per)
per: '10 seconds' // time limit
}
},
data: {
foo: 'bar'
}
},{
name: 'Weather',
provider: 'weather.com',
runs: 'getWeather', // any function on the global scope, even 'myObj.subObj.myFunc'
options: {
frequency: 'every 5 seconds',
priority: 'default',
// throttle is ignored if frequency is set --^
throttle: {
limit: 5, // how many tasks per 'provider' per limit time (per)
per: '10 seconds' // time limit
}
},
data: {
foo: 'bar'
}
}]);
var hive = new Hive({
redis: {
database: 3
}
}, [], [{
name: 'Weather',
provider: 'weather.com',
runs: 'getWeather', // any function on the global scope, even 'myObj.subObj.myFunc'
options: {
frequency: 'every 5 seconds',
priority: 'default',
// throttle is ignored if frequency is set --^
throttle: {
limit: 5, // how many tasks per 'provider' per limit time (per)
per: '10 seconds' // time limit
}
},
data: {
foo: 'bar'
}
}]);

@@ -156,27 +64,12 @@ /**

global.Hive = hive;
//hive.task.create({
// name: 'Weather',
// provider: 'weather.com',
// runs: 'getWeather', // any function on the global scope, even 'myObj.subObj.myFunc'
// options: {
// frequency: 'every 5 seconds',
// priority: 'default',
// // throttle is ignored if frequency is set --^
// throttle: {
// limit: 5, // how many tasks per 'provider' per limit time (per)
// per: '10 seconds' // time limit
// }
// },
// data: {
// foo: 'bar'
// }
//}, function () {
//
//});
process.on('SIGINT', function (cb) {
hive.shutdown(function () {
process.exit();
});
})
});

70

index.js

@@ -31,3 +31,2 @@ /**

var HiveRedis = require('./lib/services/redis');

@@ -76,10 +75,2 @@ var HiveQueue = require('./lib/services/queue');

/**
* Starts up pub/sub redis clients
* @param started
*/
setupRedis: function setupRedis(started) {
// TODO redis client for PUB/SUB inter process / cross server communication.
started();
},

@@ -90,3 +81,3 @@ /**

*/
setupIPC: ['setupRedis', function setupIPC(started) {
setupIPC: [function setupIPC(started) {
// TODO ipc (PUB/SUB)

@@ -100,3 +91,3 @@ _this.ipc = new HiveIPC(_this, _this.config);

*/
setupTasks: ['setupRedis', 'setupIPC', function setupTasks(started) {
setupTasks: ['setupIPC', function setupTasks(started) {
_this.task = new HiveTask(_this, _this.config);

@@ -110,3 +101,3 @@ _this.task.init({}, started);

*/
startQueue: ['setupRedis', 'setupIPC', 'setupTasks', function startQueue(started) {
startQueue: ['setupIPC', 'setupTasks', function startQueue(started) {
_this.queue = new HiveQueue(_this.config, _this.runner);

@@ -123,3 +114,3 @@ // clean any old workers that have been marked as orphaned for more than 5 min

*/
startScheduler: ['setupRedis', 'setupIPC', 'setupTasks', function startScheduler(started) {
startScheduler: ['setupIPC', 'setupTasks', function startScheduler(started) {
if (!_this.config.general.publisherOnly) {

@@ -143,3 +134,3 @@ if (process.env.NODE_ENV === 'development' || _this.config.general.name === 'management' || _this.config.general.scheduler) {

*/
openLanes: ['setupRedis', 'setupIPC', 'setupTasks', function openLanes(opened) {
openLanes: ['setupIPC', 'setupTasks', function openLanes(opened) {
// start lane workers

@@ -175,10 +166,12 @@ if (!_this.config.general.publisherOnly) {

*/
createUserTasks: ['setupRedis', 'setupIPC', 'setupTasks', 'openLanes', function createUserTasks(created) {
async.eachLimit(_this.tasks, 1, function (task, doneTask) {
// temp fix to allow locks to kick in - implement correct redis locking logic to fix (in schedules)
setTimeout(function () {
_this.task.create(task, doneTask);
}, (Math.floor(Math.random() * 215) + 1));
createUserTasks: ['setupIPC', 'setupTasks', 'openLanes', function createUserTasks(created) {
if (!_this.config.general.publisherOnly) {
async.eachLimit(_this.tasks, 1, function (task, doneTask) {
// temp fix to allow locks to kick in - implement correct redis locking logic to fix (in schedules)
setTimeout(function () {
_this.task.create(task, doneTask);
}, (Math.floor(Math.random() * 215) + 1));
}, created)
}, created);
} else created();
}]

@@ -212,5 +205,29 @@ }, function (error) {

stopQueue: function stopQueue(stopped) {
_this.queue.end(stopped);
// TODO fix issue with ioredis - missing a handler?
/**
* Unhandled rejection Error: Connection is closed.
at close (/Users/Mike/Documents/Homestead/projects/hive.js/node_modules/ioredis/lib/redis/event_handler.js:84:21)
at Socket.<anonymous> (/Users/Mike/Documents/Homestead/projects/hive.js/node_modules/ioredis/lib/redis/event_handler.js:59:14)
at Socket.g (events.js:260:16)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at TCP._onclose (net.js:468:12)
*/
//console.dir(_this.queue);
//console.dir(_this.queue.connection);
//if (_this.queue)
//_this.queue.end(stopped);//.catch(function () {
//stopped();
//});
//else
stopped();
},
stopIPC: function stopIPC(stopped) {
//if (_this.ipc)
// _this.ipc.end(stopped);
// else
stopped();
},
/**

@@ -221,6 +238,9 @@ * Stop scheduler gracefully.

stopScheduler: function stopScheduler(stopped) {
_this.scheduler.end(function () {
delete _this.scheduler;
//if (_this.scheduler)
// _this.scheduler.end(function () {
// delete _this.scheduler;
// stopped();
// });
//else
stopped();
});
},

@@ -227,0 +247,0 @@

@@ -113,3 +113,8 @@ var _ = require('lodash');

if (!_this.options.redis && _this.options.redisModule !== 'fakeredis') {
return _this.redis.quit();
if (this.options.redisModule !== 'ioredis')
return _this.redis.disconnect();
else
return _this.redis.quit();
}

@@ -116,0 +121,0 @@ };

@@ -28,6 +28,11 @@ /**

var util = require('util');
var connection = require("./../core/connection.js").connection;
var async = require('async');
var IPC = function IPC(hive, config) {
this.hive = hive;
this.hiveConfig = config;
this.pubClient = new connection(this.hiveConfig.redis);
this.subClient = new connection(this.hiveConfig.redis);
};

@@ -42,3 +47,46 @@

IPC.prototype.init = function init(callback) {
callback();
var _this = this;
async.parallel({
publisher: function publisher(connected) {
_this.pubClient.connect(function (err) {
connected();
});
},
subscriber: function subscriber(connected) {
_this.subClient.connect(function (err) {
_this.subClient.redis.on('message', function (channel, message) {
try {
message = JSON.parse(message)
} catch (e) {
message = {};
}
if (message.channel && message.channel == _this.hiveConfig.redis.channel) {
// if (message.src != _this.hive.id)
//console.log('Received message:', message);
// TODO event / action handlers
} else {
// TODO SUB HANDLERS
}
});
connected();
});
}
}, function () {
// sub to default hive channel
_this.subClient.redis.subscribe(_this.hiveConfig.redis.channel, function () {
_this.publish(_this.hiveConfig.redis.channel, {event: 'workerJoin', eventData: {id: _this.hive.id}});
callback();
});
});
};

@@ -53,2 +101,11 @@

var message = {
src: this.hive.id,
date: new Date(),
data: data,
channel: channel
};
this.pubClient.redis.publish(channel, JSON.stringify(message));
};

@@ -59,7 +116,18 @@

* @param channel
* @param callback
*/
IPC.prototype.subscribe = function subscribe(channel) {
IPC.prototype.subscribe = function subscribe(channel, callback) {
this.subClient.redis.subscribe(channel, callback);
};
IPC.prototype.end = function end(callback) {
var _this = this;
_this.publish(_this.hiveConfig.redis.channel, {event: 'workerExit', eventData: {id: _this.hive.id}});
// TODO end redis connections before callback
callback();
};
module.exports = IPC;

@@ -28,6 +28,12 @@ /**

var Redis = function Redis() {
var Redis = function Redis(hive, config) {
};
Redis.prototype.init = function init(callback) {
callback();
};
module.exports = Redis;

@@ -105,3 +105,6 @@ /**

console.error('--> TASK: ');
console.error(job.args[0]);
if (job)
console.error(job.args[0]);
else
console.error(job);
console.error('--> STACK TRACE: ');

@@ -122,3 +125,6 @@ console.error(failure.stack);

console.error('--> TASK: ');
console.error(job.args[0]);
if (job)
console.error(job.args[0]);
else
console.error(job);
console.error('--> STACK TRACE: ');

@@ -125,0 +131,0 @@ console.error(error.stack || error);

{
"name": "hive-dev",
"version": "1.0.14",
"version": "1.0.15",
"description": "An intelligent Redis powered, job, worker and queue library with advanced options and plugin support.",

@@ -5,0 +5,0 @@ "main": "index.js",

Sorry, the diff of this file is not supported yet

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