Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Aiden Keating committed Aug 16, 2017
1 parent 8c9d0bc commit c142281
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions lib/sync-metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,33 +148,36 @@ var getStats = function(cb) {
return input.toFixed(2) + 'ms';
}
}];
if (redisClient) {
async.map(metricsToFetch, function(metric, callback) {
var metricName = metric.metricName;
redisClient.lrange([statsNamespace, metricName].join(':'), 0, MAX_NUMBER, function(err, data) {
if (err) {
debugError('Failed to get values from redis for key %s with error : %s', metricName, err);
return callback();
}
var stats = aggregateData(metric, data);
stats.name = metric.displayName;
return callback(null, stats)
});
}, function(err, results) {

if (!redisClient) {
var errorMessage = 'Redis client is not initialised. An initial sync may not have been performed yet.';
debugError(errorMessage);
var redisClientError = new Error(errorMessage);
return cb(redisClientError);
}

async.map(metricsToFetch, function(metric, callback) {
var metricName = metric.metricName;
redisClient.lrange([statsNamespace, metricName].join(':'), 0, MAX_NUMBER, function(err, data) {
if (err) {
return cb(err);
debugError('Failed to get values from redis for key %s with error : %s', metricName, err);
return callback();
}
var reduced = _.reduce(results, function(sofar, result) {
sofar[result.name] = result;
delete result.name;
return sofar;
}, {});
return cb(null, reduced);
var stats = aggregateData(metric, data);
stats.name = metric.displayName;
return callback(null, stats)
});
} else {
var redisClientError = new Error('Redis client is not initialised. An initial sync may not have been performed yet.');
return cb(redisClientError);
}
}, function(err, results) {
if (err) {
return cb(err);
}
var reduced = _.reduce(results, function(sofar, result) {
sofar[result.name] = result;
delete result.name;
return sofar;
}, {});
return cb(null, reduced);
});
};

module.exports = {
Expand Down

0 comments on commit c142281

Please sign in to comment.