Skip to content

Commit

Permalink
parallel application ip checks for non g processing
Browse files Browse the repository at this point in the history
  • Loading branch information
Cabecinha84 committed Aug 1, 2024
1 parent 2b7b186 commit d3e4ee0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/services/application/checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const config = require('config');
const https = require('https');
const ethers = require('ethers');
const serviceHelper = require('../serviceHelper');
const domainService = require('../domainService');
const log = require('../../lib/log');

const timeout = 5456;
Expand Down Expand Up @@ -795,7 +796,9 @@ async function checkApplication(app, ip) {
isOK = await checkEthers(ip.split(':')[0], ethersList[matchIndex].port, ethersList[matchIndex].providerURL, ethersList[matchIndex].cmd);
}
}
return isOK;
if(isOK) {
domainService.addAppIp(ip);
}
}

setInterval(async () => {
Expand Down
24 changes: 18 additions & 6 deletions src/services/domainService.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ async function selectIPforG(ips, app) {
return null;
}

let appIps = [];
function addAppIp(ip) {
appIps.push(ip);
}
// periodically keeps HAproxy ans certificates updated every 4 minutes
async function generateAndReplaceMainApplicationHaproxyConfig(isGmode = false, timeout = 30) {
try {
Expand Down Expand Up @@ -324,7 +328,7 @@ async function generateAndReplaceMainApplicationHaproxyConfig(isGmode = false, t
appLocations.push({ ip: '167.114.217.138' });
}
if (appLocations.length > 0) {
let appIps = [];
appIps = [];
let isG = false;
if (app.version <= 3) {
if (app.containerData.includes('g:')) {
Expand All @@ -351,13 +355,20 @@ async function generateAndReplaceMainApplicationHaproxyConfig(isGmode = false, t
const applicationWithChecks = applicationChecks.applicationWithChecks(app);
log.info(`Application ${app.name} have specific checks: ${applicationWithChecks}`);
if (applicationWithChecks) {
for (const location of appLocations) { // run coded checks for app
// eslint-disable-next-line no-await-in-loop
const isOk = await applicationChecks.checkApplication(app, location.ip);
if (isOk) {
appIps.push(location.ip);
let promiseArray = [];
for (const [i, location] of appLocations.entries()) { // run coded checks for app
promiseArray.push(applicationChecks.checkApplication(app, location.ip));
if ((i + 1) % 25 === 0) {
// eslint-disable-next-line no-await-in-loop
await Promise.allSettled(promiseArray);
promiseArray = [];
}
}
if (promiseArray.length > 0) {
// eslint-disable-next-line no-await-in-loop
await Promise.allSettled(promiseArray);
promiseArray = [];
}
} else {
appIps = appLocations.map((location) => location.ip);
}
Expand Down Expand Up @@ -742,4 +753,5 @@ async function start() {

module.exports = {
start,
addAppIp,
};

0 comments on commit d3e4ee0

Please sign in to comment.