Fix: Correct support for multiple nodes.json files.
This commit is contained in:
parent
966a714f77
commit
f12ef87567
|
@ -418,41 +418,58 @@ angular.module('ffffng')
|
|||
});
|
||||
}
|
||||
|
||||
function retrieveNodeInformationForUrl(url, callback) {
|
||||
function withUrlsData(urls, callback) {
|
||||
async.map(urls, function (url, urlCallback) {
|
||||
Logger.tag('monitoring', 'information-retrieval').debug('Retrieving nodes.json: %s', url);
|
||||
request(url, function (err, response, body) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
return urlCallback(err);
|
||||
}
|
||||
|
||||
if (response.statusCode !== 200) {
|
||||
return callback(new Error(
|
||||
return urlCallback(new Error(
|
||||
'Could not download nodes.json from ' + url + ': ' +
|
||||
response.statusCode + ' - ' + response.statusMessage
|
||||
));
|
||||
}
|
||||
|
||||
parseNodesJson(body, function (err, data) {
|
||||
parseNodesJson(body, urlCallback);
|
||||
});
|
||||
}, callback);
|
||||
}
|
||||
|
||||
function retrieveNodeInformationForUrls(urls, callback) {
|
||||
withUrlsData(urls, function (err, datas) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (previousImportTimestamp !== null && !data.importTimestamp.isAfter(previousImportTimestamp)) {
|
||||
var maxTimestamp = datas[0].importTimestamp;
|
||||
_.each(datas, function (data) {
|
||||
if (data.importTimestamp.isAfter(maxTimestamp)) {
|
||||
maxTimestamp = data.importTimestamp;
|
||||
}
|
||||
});
|
||||
|
||||
if (previousImportTimestamp !== null && !maxTimestamp.isAfter(previousImportTimestamp)) {
|
||||
Logger
|
||||
.tag('monitoring', 'information-retrieval')
|
||||
.debug(
|
||||
'No new data, skipping. Current timestamp: %s, previous timestamp: %s',
|
||||
data.importTimestamp.format(),
|
||||
maxTimestamp.format(),
|
||||
previousImportTimestamp.format()
|
||||
);
|
||||
return callback();
|
||||
}
|
||||
previousImportTimestamp = data.importTimestamp;
|
||||
previousImportTimestamp = maxTimestamp;
|
||||
|
||||
// We do not parallelize here as the sqlite will start slowing down and blocking with too many
|
||||
// parallel queries. This has resulted in blocking other requests too and thus in a major slowdonw.
|
||||
var nodes = _.flatMap(datas, function (data) {
|
||||
return data.nodes;
|
||||
});
|
||||
async.eachSeries(
|
||||
data.nodes,
|
||||
nodes,
|
||||
function (nodeData, nodeCallback) {
|
||||
Logger.tag('monitoring', 'information-retrieval').debug('Importing: %s', nodeData.mac);
|
||||
|
||||
|
@ -492,11 +509,10 @@ angular.module('ffffng')
|
|||
return callback(err);
|
||||
}
|
||||
|
||||
markMissingNodesAsOffline(data.nodes, callback);
|
||||
markMissingNodesAsOffline(nodes, callback);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
|
@ -636,11 +652,14 @@ angular.module('ffffng')
|
|||
|
||||
retrieveNodeInformation: function (callback) {
|
||||
var urls = config.server.map.nodesJsonUrl;
|
||||
if (_.isEmpty(urls)) {
|
||||
return callback(null);
|
||||
}
|
||||
if (_.isString(urls)) {
|
||||
urls = [urls];
|
||||
}
|
||||
|
||||
async.eachSeries(urls, retrieveNodeInformationForUrl, callback);
|
||||
retrieveNodeInformationForUrls(urls, callback);
|
||||
},
|
||||
|
||||
sendMonitoringMails: function (callback) {
|
||||
|
|
Loading…
Reference in a new issue