1
0
mirror of https://github.com/nttgin/BGPalerter.git synced 2024-05-19 06:50:08 +00:00

reduced memory usage of generate command

This commit is contained in:
Massimo Candela
2022-01-28 03:36:11 +01:00
parent dd17779311
commit f9a5f1bab8

View File

@@ -8,10 +8,8 @@ import { AS } from "./model";
const apiTimeout = 120000;
const clientId = "ntt-bgpalerter";
const rpki = new RpkiValidator({clientId});
import axiosEnrich from "./utils/axiosEnrich";
module.exports = function generatePrefixes(inputParameters) {
let {
asnList,
@@ -31,6 +29,8 @@ module.exports = function generatePrefixes(inputParameters) {
downstreams
} = inputParameters;
const rpki = new RpkiValidator({clientId});
exclude = exclude || [];
logger = logger || console.log;
group = group || "noc";
@@ -347,7 +347,17 @@ module.exports = function generatePrefixes(inputParameters) {
logger(`Cannot download more specific prefixes ${e}`);
})
})
.then(() => rpki.preCache())
.then(() => {
return rpki.getAvailableConnectors()
.then((connectors) => {
rpki.setConnector(connectors[0]);
if (Object.keys(generateList).length > 2000) {
return rpki.preCache();
}
})
.catch(() => rpki.preCache());
})
.then(() => { // Check
return Promise
.all(Object.keys(generateList).map(prefix => validatePrefix(generateList[prefix].asn[0], prefix)))
@@ -381,7 +391,7 @@ module.exports = function generatePrefixes(inputParameters) {
return batchPromises(1, asnList, getNeighbors)
.then(asnNeighbors => {
generateMonitoredAsObject(createASesRules, asnNeighbors);
})
});
// Otherwise nothing
})
.then(() => {