Skip to content
This repository was archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
refactor to a more consistent interface
Browse files Browse the repository at this point in the history
  • Loading branch information
scoates committed Apr 12, 2013
1 parent 51ed263 commit eaf0f22
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions plugin/mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ var shared = require('./shared');
module.exports = function (service) {
var pending = 0;

var doCount = function (conn, from, funneler, collection) {
conn.collection(collection, function (err, coll) {
var doCount = function (conn, from, funneler, serviceName, thisService) {
conn.collection(serviceName, function (err, coll) {
pending++;
coll.count(function (err, count) {
pending--;
funneler({
'funnel': 'mongo',
'nodeName': from.replace(/^mongodb:\/\//, ''),
'serviceName': collection,
'serviceName': serviceName,
'metricName': 'count',
'reading': count
});
Expand All @@ -22,10 +22,10 @@ module.exports = function (service) {
});
};

var doQuery = function (conn, from, funneler, serviceName, collection, query) {
conn.collection(collection, function (err, coll) {
var doQuery = function (conn, from, funneler, serviceName, thisService) {
conn.collection(thisService.collection, function (err, coll) {
pending++;
coll.count(query, function (err, count) {
coll.count(thisService.query, function (err, count) {
pending--;
funneler({
'funnel': 'mongo',
Expand All @@ -41,18 +41,18 @@ module.exports = function (service) {
});
};

var doAggregate = function (conn, from, funneler, serviceName, collection, aggregate, processor) {
conn.collection(collection, function (err, coll) {
var doAggregate = function (conn, from, funneler, serviceName, thisService) {
conn.collection(thisService.collection, function (err, coll) {
pending++;
coll.aggregate(aggregate, function (err, result) {
coll.aggregate(thisService.aggregate, function (err, result) {
pending--;
if (result) {
funneler({
'funnel': 'mongo',
'nodeName': from.replace(/^mongodb:\/\//, ''),
'serviceName': serviceName,
'metricName': 'aggregate',
'reading': processor(result),
'reading': thisService.processor(result),
});
}
if (pending == 0) {
Expand All @@ -73,11 +73,11 @@ module.exports = function (service) {
for (var serviceName in service.services) {
(function (thisService) {
if (thisService === shared.COUNT || thisService.count) {
doCount(conn, from, funneler, serviceName);
doCount(conn, from, funneler, serviceName, thisService);
} else if (thisService.query) {
doQuery(conn, from, funneler, serviceName, thisService.collection, thisService.query);
doQuery(conn, from, funneler, serviceName, thisService);
} else if (thisService.aggregate) {
doAggregate(conn, from, funneler, serviceName, thisService.collection, thisService.aggregate, thisService.processor);
doAggregate(conn, from, funneler, serviceName, thisService);
}
})(service.services[serviceName]);
}
Expand Down

0 comments on commit eaf0f22

Please sign in to comment.