Skip to content

Commit 62aa6b0

Browse files
committed
change mongo back to setInterval
1 parent f435e64 commit 62aa6b0

File tree

1 file changed

+44
-44
lines changed

1 file changed

+44
-44
lines changed

chronos_npm_package/controllers/mongo.js

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -827,51 +827,51 @@ mongo.setQueryOnInterval = async config => {
827827

828828
console.log('currentMetricNames.length: ', Object.keys(currentMetricNames).length);
829829
// Use setInterval to send queries to metrics server and then pipe responses to database
830-
// setInterval(() => {
831-
metricsQuery(config)
832-
// This updates the Metrics Model with all chosen metrics. If there are no chosen metrics it sets all available metrics as chosen metrics within the metrics model.
833-
.then(async parsedArray => {
834-
//await mongo.createGrafanaDashboards(config, parsedArray);
835-
console.log('parsedArray.length is: ', parsedArray.length);
836-
// This conditional would be used if new metrics are available to be tracked.
837-
if (length !== parsedArray.length) {
838-
// for (let metric of parsedArray) {
839-
// if (!(metric.metric in currentMetricNames)) {
840-
// await model.create(metric);
841-
// //currentMetricNames[metric] = true;
842-
// }
830+
setInterval(() => {
831+
metricsQuery(config)
832+
// This updates the Metrics Model with all chosen metrics. If there are no chosen metrics it sets all available metrics as chosen metrics within the metrics model.
833+
.then(async parsedArray => {
834+
//await mongo.createGrafanaDashboards(config, parsedArray);
835+
console.log('parsedArray.length is: ', parsedArray.length);
836+
// This conditional would be used if new metrics are available to be tracked.
837+
if (length !== parsedArray.length) {
838+
// for (let metric of parsedArray) {
839+
// if (!(metric.metric in currentMetricNames)) {
840+
// await model.create(metric);
841+
// //currentMetricNames[metric] = true;
842+
// }
843+
// }
844+
length = await mongo.addMetrics(parsedArray, config.mode, currentMetricNames, model);
845+
}
846+
// const documents = [];
847+
// for (const metric of parsedArray) {
848+
// /**
849+
// * This will check if the current metric in the parsed array
850+
// * evaluates to true within the currentMetricNames object
851+
// * which is updated by the user when they select/deselect metrics on the electron app
852+
// * helping to avoid overloading the db with unnecessary data.
853+
// */
854+
855+
// if (currentMetricNames[metric.metric]) documents.push(model(metric));
843856
// }
844-
length = await mongo.addMetrics(parsedArray, config.mode, currentMetricNames, model);
845-
}
846-
// const documents = [];
847-
// for (const metric of parsedArray) {
848-
// /**
849-
// * This will check if the current metric in the parsed array
850-
// * evaluates to true within the currentMetricNames object
851-
// * which is updated by the user when they select/deselect metrics on the electron app
852-
// * helping to avoid overloading the db with unnecessary data.
853-
// */
854-
855-
// if (currentMetricNames[metric.metric]) documents.push(model(metric));
856-
// }
857-
// await model.insertMany(parsedArray, err => {
858-
// if (err) {
859-
// console.error(err)
860-
// } else {
861-
// console.log(`${config.mode} metrics recorded in MongoDB`)
862-
// }
863-
// });
864-
let allMetrics = await model.find({});
865-
console.log('allMetrics.length: ', allMetrics.length);
866-
console.log("🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 start creating dashboards 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡")
867-
await mongo.createGrafanaDashboards(config, allMetrics);
868-
console.log("✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ finish creating dashboards ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅")
869-
})
870-
// .then(() => {
871-
// console.log(`${config.mode} metrics recorded in MongoDB`)
872-
// })
873-
.catch(err => console.log(`Error inserting ${config.mode} documents in MongoDB: `, err));
874-
// }, 40000);
857+
// await model.insertMany(parsedArray, err => {
858+
// if (err) {
859+
// console.error(err)
860+
// } else {
861+
// console.log(`${config.mode} metrics recorded in MongoDB`)
862+
// }
863+
// });
864+
let allMetrics = await model.find({});
865+
console.log('allMetrics.length: ', allMetrics.length);
866+
console.log("🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 start creating dashboards 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡")
867+
await mongo.createGrafanaDashboards(config, allMetrics);
868+
console.log("✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ finish creating dashboards ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅")
869+
})
870+
// .then(() => {
871+
// console.log(`${config.mode} metrics recorded in MongoDB`)
872+
// })
873+
.catch(err => console.log(`Error inserting ${config.mode} documents in MongoDB: `, err));
874+
}, 40000);
875875
};
876876

877877
mongo.getSavedMetricsLength = async (mode, currentMetricNames) => {

0 commit comments

Comments
 (0)