Skip to content

Commit

Permalink
remove mandatory app
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTrunk committed Jan 28, 2024
1 parent b49bb66 commit fe4c53a
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 16 deletions.
2 changes: 1 addition & 1 deletion config/appsConfig.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
mandatoryApps: ['explorer', 'web', 'themok6', 'paoverview', 'eckodexswap'],
mandatoryApps: ['explorer', 'web', 'themok6', 'paoverview'],
ownersApps: [], // Will retrieve only apps of owners specified here
whiteListedApps: [], // If there's app in the array, blacklisting will be ignore
blackListedApps: ['Kadena', 'Kadena2', 'PresearchNode*', 'BrokerNode*', 'Folding*'],
Expand Down
81 changes: 66 additions & 15 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,72 @@
const dns = require('dns').promises;

async function dnsLookup(hostname) {
const timeoutPromise = new Promise((resolve) => {
setTimeout(resolve, 2000, []);
});
const dnsPromise = dns.lookup(hostname, { all: true }).catch((error) => console.log(error)); // eg. [ { address: '65.21.189.1', family: 4 } ]
const result = await Promise.race([dnsPromise, timeoutPromise]);
return result || [];
async function selectIPforG(ips, app) {
// choose the ip address whose sum of digits is the lowest
if (ips && ips.length) {
let chosenIp = ips[0];
let chosenIpSum = ips[0].split(':')[0].split('.').reduce((a, b) => parseInt(a, 10) + parseInt(b, 10), 0);
for (const ip of ips) {
const sum = ip.split(':')[0].split('.').reduce((a, b) => parseInt(a, 10) + parseInt(b, 10), 0);
if (sum < chosenIpSum) {
chosenIp = ip;
chosenIpSum = sum;
}
}
const isOk = false;
if (isOk) {
return chosenIp;
}
console.log(ips);
const newIps = ips.filter((ip) => ip !== chosenIp);
if (newIps.length) {
return selectIPforG(newIps, app);
}
}
return null;
}

async function test() {
try {
const resp = await dnsLookup('www.astro-fun.com');
console.log(resp);
} catch (error) {
console.log(error);
}
const b = await selectIPforG(['123.234','2345.342','456.34234','342.434'], 'test');
console.log(b);
}

test();

const recentlyConfiguredApps = [{
appName: 'test1',
ips: ['1'],
},
{
appName: 'test2',
ips: ['1'],
},
{
appName: 'test',
ips: ['1'],
},
{
appName: 'test3',
ips: ['1'],
}];
let configuredApps = [{
appName: 'test',
ips: ['2'],
},
{
appName: 'test3',
ips: ['2'],
}];
const updatingConfig = JSON.parse(JSON.stringify(recentlyConfiguredApps));
// merge recentlyConfiguredApps with currently configuredApps
for (const app of configuredApps) {
let appExists = updatingConfig.find((a) => a.appName === app.appName);
if (!appExists) {
updatingConfig.push(app);
} else {
updatingConfig.splice(updatingConfig.indexOf(appExists), 1, app);
// console.log(app);
// appExists = app; // this is also updating element in updatingConfig
}
}
console.log(updatingConfig);
configuredApps = updatingConfig;

console.log(configuredApps);

0 comments on commit fe4c53a

Please sign in to comment.