Comparing version 0.0.8 to 0.0.9
@@ -1,6 +0,3 @@ | ||
var closeDB = function(com) { | ||
com.db.close(); | ||
com.cb(com.err, 'Connection closed'); | ||
module.exports = function(db, cb) { | ||
db.close(cb); | ||
}; | ||
module.exports = closeDB; |
@@ -1,2 +0,2 @@ | ||
var commons = { | ||
module.export = { | ||
"inc": 1, | ||
@@ -6,7 +6,7 @@ "doc": {}, | ||
"project": {}, | ||
"limit": 10, | ||
"index": "_id", | ||
"limit": 10, | ||
"pooling": false, | ||
"sort": {"_id": 1}, | ||
"options": {"w": 1}, | ||
"sort": {"_id": 1}, | ||
"concern": {"w": 1}, | ||
"collection": "remo", | ||
@@ -16,3 +16,1 @@ "url": "mongodb://127.0.0.1/remo", | ||
}; | ||
module.export = commons; |
var connect = function(com, next) { | ||
com.stime = new Date().getTime(); | ||
var client = require('mongodb').MongoClient; | ||
if(!com){ return console.log('Com not found.'); } | ||
if(com.db){ | ||
return next(com); | ||
}else{ | ||
if(!com) { return console.log('Missing com object.'); } | ||
if(!com.url) { return console.log('Missing db url.'); } | ||
if(com.db) { | ||
next(com); | ||
} else { | ||
var stime = new Date().getTime(); | ||
var merge = require('../api/merge'); | ||
var client = require('mongodb').MongoClient; | ||
client.connect(com.url, function(err, db) { | ||
com.err = err; | ||
com.db = db || false; | ||
next(com); | ||
next(merge(com, {err: err, db: db, stime: stime})); | ||
}); | ||
@@ -14,0 +15,0 @@ } |
@@ -1,8 +0,8 @@ | ||
var count = function(db, message, cb) { | ||
module.exports = function(db, message, cb) { | ||
var col = db.collection(message.collection); | ||
col.count(message.query, function(err, results) { | ||
cb(err, results); | ||
}); | ||
col.count(message.query, | ||
function(err, results) { | ||
cb(err, results); | ||
} | ||
); | ||
}; | ||
module.exports = count; |
@@ -1,10 +0,7 @@ | ||
var create = function(props) { | ||
this.connect(this.merge( this.props, props ), function(com){ | ||
com.db.createCollection(com.collection, function(err, collection) { | ||
com.db.close(); | ||
com.cb(err, collection); | ||
}); | ||
}); | ||
module.exports = function(db, message, cb) { | ||
db.createCollection(message.collection, | ||
function(err, results) { | ||
cb(err, results); | ||
} | ||
); | ||
}; | ||
module.exports = create; |
@@ -1,11 +0,8 @@ | ||
var createIndex = function(props) { | ||
this.connect(this.merge( this.props, props ), function(com){ | ||
var col = com.db.collection( com.collection ); | ||
col.createIndex(com.query, function(err, results) { | ||
com.db.close(); | ||
com.cb(err, results); | ||
}); | ||
}); | ||
module.exports = function(db, message, cb) { | ||
var col = db.collection(message.collection); | ||
col.createIndex(message.query, | ||
function(err, results) { | ||
cb(err, results); | ||
} | ||
); | ||
}; | ||
module.exports = createIndex; |
@@ -1,12 +0,6 @@ | ||
var drop = function(props) { | ||
this.connect(this.merge( this.props, props ), function(com){ | ||
var col = com.db.collection( com.collection ); | ||
col.drop(function(err, results) { | ||
com.db.close(); | ||
com.cb(err, results); | ||
}); | ||
module.exports = function(db, cb) { | ||
var col = db.collection(message.collection); | ||
col.drop(function(err, results) { | ||
cb(err, results); | ||
}); | ||
}; | ||
module.exports = drop; |
@@ -1,10 +0,5 @@ | ||
var dropDatabase = function(props) { | ||
this.connect(this.merge( this.props, props ),function(com) { | ||
com.db.dropDatabase(function(err, results) { | ||
com.db.close(); | ||
com.cb(err, results); | ||
}); | ||
module.exports = function(db, message, cb) { | ||
db.dropDatabase(function(err, results) { | ||
cb(err, results); | ||
}); | ||
}; | ||
module.exports = dropDatabase; |
@@ -1,11 +0,8 @@ | ||
var createIndex = function(props) { | ||
this.connect(this.merge( this.props, props ), function(com){ | ||
var col = com.db.collection(com.name); | ||
col.dropIndex(com.query, function(err, results) { | ||
com.db.close(); | ||
com.cb(err, results); | ||
}); | ||
}); | ||
module.exports = function(db, message, cb) { | ||
var col = db.collection(message.collection); | ||
col.dropIndex(message.query, | ||
function(err, results) { | ||
cb(err, results); | ||
} | ||
); | ||
}; | ||
module.exports = createIndex; |
@@ -1,2 +0,2 @@ | ||
var find = function(db, message, cb) { | ||
module.exports = function(db, message, cb) { | ||
var col = db.collection(message.collection); | ||
@@ -10,3 +10,1 @@ col.find(message.query, message.project, message.options) | ||
}; | ||
module.exports = find; |
@@ -1,14 +0,11 @@ | ||
var parseOId = require('./parseOId'); | ||
var parseOId = require('../api/parseOId'); | ||
var findByObjectId = function(props) { | ||
this.connect(this.merge( this.props, props ), function(com) { | ||
com.query[com.index] = parseOId(com.query[com.index]); | ||
var col = com.db.collection(com.collection); | ||
col.findOne(com.query, function(err, results) { | ||
com.db.close(); | ||
com.cb(err, results); | ||
}); | ||
}); | ||
module.exports = function(db, message, cb) { | ||
var col = db.collection(message.collection); | ||
message.query[message.index] = parseOId(message.query[message.index]); | ||
col.findOne(message.query, | ||
function(err, results) { | ||
cb(err, results); | ||
} | ||
); | ||
}; | ||
module.exports = findByObjectId; |
@@ -1,2 +0,2 @@ | ||
var findOne = function(db, message, cb) { | ||
module.exports = function(db, message, cb) { | ||
var col = db.collection(message.collection); | ||
@@ -8,3 +8,1 @@ col.findOne(message.query, message.project, message.options) | ||
}; | ||
module.exports = findOne; |
@@ -1,8 +0,6 @@ | ||
var update = require('./update'); | ||
var update = require('../api/update'); | ||
var inc = function(db, message, cb) { | ||
message.doc = {$inc: message.inc}; | ||
module.exports = function(db, message, cb) { | ||
message.doc = {$inc: message.doc}; | ||
update(db, message, cb); | ||
}; | ||
module.exports = inc; |
@@ -1,8 +0,8 @@ | ||
var insert = function(db, message, cb) { | ||
module.exports = function(db, message, cb) { | ||
var col = db.collection(message.collection); | ||
col.insert(message.doc, function(err, results) { | ||
cb(err, results); | ||
}); | ||
col.insert(message.doc, | ||
function(err, results) { | ||
cb(err, results); | ||
} | ||
); | ||
}; | ||
module.exports = insert; |
@@ -1,5 +0,3 @@ | ||
/** | ||
* Rewrite old properties with new ones. | ||
*/ | ||
var merge = function(props, newProps) { | ||
// Rewrite old properties with new ones. | ||
module.exports = function(props, newProps) { | ||
for(var p in newProps) { | ||
@@ -12,3 +10,1 @@ if (newProps.hasOwnProperty(p)) { | ||
}; | ||
module.exports = merge; |
@@ -1,6 +0,6 @@ | ||
var multi = function(props) { | ||
this.props.options.multi = true; | ||
this.update(this.merge( this.props, props )); | ||
var update = require('../api/update'); | ||
module.exports = function(db, message, cb) { | ||
message.options.multi = true; | ||
update(db, message, cb); | ||
}; | ||
module.exports = multi; |
var ObjectID = require('mongodb').ObjectID; | ||
var parseOId = function(value){ | ||
try{ | ||
module.exports = function(value) { | ||
try { | ||
return new ObjectID.createFromHexString(value); | ||
}catch(e){ | ||
} catch(e) { | ||
return { | ||
@@ -13,3 +13,1 @@ code: 'NotValidHex', | ||
}; | ||
module.exports = parseOId; |
@@ -1,11 +0,8 @@ | ||
var remove = function(props) { | ||
this.connect(this.merge( this.props, props ), function(com){ | ||
var col = com.db.collection(com.collection); | ||
col.remove(com.query, function(err, results) { | ||
com.db.close(); | ||
com.cb(err, results); | ||
}); | ||
}); | ||
module.exports = function(db, message, cb) { | ||
var col = db.collection(message.collection); | ||
col.remove(message.query, | ||
function(err, results) { | ||
cb(err, results); | ||
} | ||
); | ||
}; | ||
module.exports = remove; |
@@ -1,14 +0,11 @@ | ||
var parseOId = require('./parseOId'); | ||
var parseOId = require('../api/parseOId'); | ||
var removeByObjectId = function(props) { | ||
this.connect(this.merge( this.props, props ), function(com){ | ||
com.query[com.key] = parseOId(com.query[com.key]); | ||
var col = com.db.collection(com.collection); | ||
col.remove(com.query, function(err, results) { | ||
com.db.close(); | ||
com.cb(err, results); | ||
}); | ||
}); | ||
module.exports = function(db, message, cb) { | ||
var col = db.collection(message.collection); | ||
message.query[message.index] = parseOId(message.query[message.index]); | ||
col.remove(message.query, | ||
function(err, results) { | ||
cb(err, results); | ||
} | ||
); | ||
}; | ||
module.exports = removeByObjectId; |
@@ -1,7 +0,6 @@ | ||
var response = function(com) { | ||
com.etime = new Date().getTime(); | ||
com.ttime = com.etime - com.stime; | ||
//console.log( com.ttime ); | ||
if(com){ | ||
if(com.db){ | ||
module.exports = function(com) { | ||
if(com && !com.pooling) { | ||
if(com.db) { | ||
com.etime = new Date().getTime(); | ||
com.ttime = com.etime - com.stime; | ||
com.db.close(); | ||
@@ -11,3 +10,1 @@ } | ||
}; | ||
module.exports = response; |
@@ -1,8 +0,6 @@ | ||
var update = require('./update'); | ||
var update = require('../api/update'); | ||
var set = function(db, message, cb) { | ||
module.exports = function(db, message, cb) { | ||
message.doc = {$set: message.doc}; | ||
update(db, message, cb); | ||
}; | ||
module.exports = set; |
@@ -1,7 +0,6 @@ | ||
var update = require('./update'); | ||
var update = require('../api/update'); | ||
var unset = function(db, message, cb) { | ||
module.exports = function(db, message, cb) { | ||
message.doc = {$unset: message.doc}; | ||
update(db, message, cb); | ||
}; | ||
module.exports = unset; |
@@ -1,4 +0,4 @@ | ||
var update = function(db, message, cb) { | ||
module.exports = function(db, message, cb) { | ||
var col = db.collection(message.collection); | ||
col.update(message.query, message.doc, message.concern, | ||
col.update(message.query, message.doc, message.options, | ||
function(err, results) { | ||
@@ -9,3 +9,1 @@ cb(err, results); | ||
}; | ||
module.exports = update; |
@@ -1,15 +0,7 @@ | ||
var parseOId = require('./parseOId'); | ||
var update = require('../api/update'); | ||
var parseOId = require('../api/parseOId'); | ||
var updateByObjectId = function(props) { | ||
this.connect(this.merge( this.props, props ), function(com){ | ||
var col = com.db.collection(com.collection); | ||
com.query[com.key] = parseOId(com.query[com.key]); | ||
col.update(com.query, com.doc, com.concern, function(err, results) { | ||
com.db.close(); | ||
com.cb(err, results); | ||
}); | ||
}); | ||
module.exports = function(db, message, cb) { | ||
message.query[message.index] = parseOId(message.query[message.index]); | ||
update(db, message, cb); | ||
}; | ||
module.exports = updateByObjectId; |
@@ -1,7 +0,6 @@ | ||
var upsert = function(props) { | ||
this.options = { upsert: true }; | ||
this.props.doc.$unset[props.key] = 1; | ||
this.update(this.merge( this.props, props )); | ||
var update = require('../api/update'); | ||
module.exports = function(db, message, cb) { | ||
message.options.upsert = true; | ||
update(db, message, cb); | ||
}; | ||
module.exports = upsert; |
@@ -17,7 +17,7 @@ { | ||
"project": {}, | ||
"limit": 10, | ||
"index": "_id", | ||
"limit": 10, | ||
"sort": {"_id": 1}, | ||
"pooling": false, | ||
"options": {"w": 1}, | ||
"sort": {"_id": 1}, | ||
"concern": {"w": 1}, | ||
"collection": "remo", | ||
@@ -24,0 +24,0 @@ "url": "mongodb://127.0.0.1/remo" |
@@ -6,13 +6,14 @@ var remo = require('../index'); | ||
case 'set': | ||
case 'inc': | ||
case 'find': | ||
case 'unset': | ||
case 'count': | ||
case 'insert': | ||
case 'update': | ||
case 'findOne': | ||
case 'inc': | ||
case 'count': | ||
remo[m.action].apply(this, [db, m, cb]); | ||
break; | ||
default: | ||
return 'Non processable attempt'; | ||
cb('Non processable attempt'); | ||
break; | ||
} | ||
@@ -19,0 +20,0 @@ }; |
@@ -5,3 +5,3 @@ var redis = require('redis'); | ||
var push = function(message){ | ||
var push = function(message) { | ||
pub.rpush( | ||
@@ -16,7 +16,14 @@ [ | ||
var iteration = function(){ | ||
var iteration = function() { | ||
for (var i=0; i<2000; i++) { | ||
push({ | ||
collection: 'mine', | ||
doc: {version: i, module: 'send'}, | ||
action: 'unknown' | ||
}); | ||
push({ | ||
collection: 'mine', | ||
doc: {version: i, module: 'send'}, | ||
action: 'insert' | ||
@@ -23,0 +30,0 @@ }); |
@@ -7,21 +7,22 @@ var redis = require('redis'); | ||
var merge = require('../api/merge'); | ||
var connect = require('../api/connect'); | ||
var empty = function(){}; | ||
var attemptOne = function(msg, db){ | ||
var attemptOne = function(msg, db) { | ||
try { | ||
var message = JSON.parse(msg); | ||
if(message===null){ return; } | ||
if(!message || !message.action){ | ||
if(message===null) { return; } | ||
if(!message || !message.action) { | ||
subR.lpush([conf.queue.retry, msg], empty); | ||
}else{ | ||
attempt(db, merge(require('../api/commons'), message), function(err, res){ | ||
if(err){ | ||
attempt(db, merge(conf.defaults, message), function(err, res) { | ||
if(err) { | ||
subR.lpush([conf.queue.retry, msg], empty); | ||
subR.lpush([conf.queue.error, JSON.stringify(err)], empty); | ||
}else{ | ||
} else { | ||
if(message.action==='find'){ | ||
subR.lpush([conf.queue.output, JSON.stringify(res)], empty); | ||
}else{ | ||
} else { | ||
subR.lpush([conf.queue.results, JSON.stringify(res)], empty); | ||
@@ -38,3 +39,3 @@ } | ||
var attemptAll = function(size, db){ | ||
var attemptAll = function(size, db) { | ||
@@ -58,4 +59,3 @@ var numIt = (size > conf.queue.size) ? conf.queue.size : size; | ||
mongo.connect(conf.defaults.url, function(err, db) { | ||
connect(merge(conf.defaults, {pooling: true}), function(err, db) { | ||
setInterval( function() { | ||
@@ -66,3 +66,3 @@ subR.llen(conf.queue.input, function(err, size) { | ||
} | ||
console.log(process.memoryUsage()); | ||
@@ -69,0 +69,0 @@ }); |
{ | ||
"name": "remo", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "Re[dis]Mo[ngo] queue manager", | ||
@@ -24,6 +24,7 @@ "main": "index.js", | ||
"dinam", | ||
"alive" | ||
"alive", | ||
"stats" | ||
], | ||
"dependencies": { | ||
"mongodb": "^2.0.25", | ||
"mongodb": "^2.0.33", | ||
"redis": "^0.12.1" | ||
@@ -30,0 +31,0 @@ }, |
@@ -150,8 +150,1 @@ # ReMo | ||
## ToDo | ||
* Remove code complexity. | ||
* Separate by function. [OK] | ||
* Export all in one file. [OK] | ||
* Add inc, set, unset, upsert functions. [Ok] | ||
* Use lower case for naming. [OK] | ||
* Remove prototype functions. [OK] |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15682
425
150
Updatedmongodb@^2.0.33