Skip to content

Commit

Permalink
point to correct fdm index based on appname
Browse files Browse the repository at this point in the history
  • Loading branch information
Cabecinha84 committed Jan 4, 2024
1 parent 45a366a commit 6ec765d
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions ZelBack/src/services/appsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -10549,10 +10549,20 @@ async function masterSlaveApps() {
const identifier = installedApp.name;
const appId = dockerService.getAppIdentifier(identifier);
if (installedApp.containerData.includes('g:') && receiveOnlySyncthingAppsCache.get(appId).restarted) {
let fdmIndex = 1;
const appNameFirstLetterLowerCase = installedApp.name.substring(1, 1).toLowerCase();
if (appNameFirstLetterLowerCase.match(/[h-n]/)) {
fdmIndex = 2;
} else if (appNameFirstLetterLowerCase.match(/[o-u]/)) {
fdmIndex = 3;
} else if (appNameFirstLetterLowerCase.match(/[v-z]/)) {
fdmIndex = 4;
}
log.info(`masterSlaveApps: fdmIndex:${fdmIndex}`);
let ip = null;
let serverStatus = null;
// eslint-disable-next-line no-await-in-loop
let fdmEUData = await serviceHelper.axiosGet(`https://fdm-fn-1-4.runonflux.io/fluxstatistics?scope=${installedApp.name};json;norefresh`, axiosOptions).catch((error) => {
let fdmEUData = await serviceHelper.axiosGet(`https://fdm-fn-1-${fdmIndex}.runonflux.io/fluxstatistics?scope=${installedApp.name};json;norefresh`, axiosOptions).catch((error) => {
log.error(`masterSlaveApps: Failed to reach EU FDM with error: ${error}`);
});
fdmEUData = fdmEUData.data;
Expand All @@ -10566,7 +10576,7 @@ async function masterSlaveApps() {
}
if (!ip || !serverStatus) {
// eslint-disable-next-line no-await-in-loop
let fdmUSAData = await serviceHelper.axiosGet(`https://fdm-usa-1-4.runonflux.io/fluxstatistics?scope=${installedApp.name};json;norefresh`, axiosOptions).catch((error) => {
let fdmUSAData = await serviceHelper.axiosGet(`https://fdm-usa-1-${fdmIndex}.runonflux.io/fluxstatistics?scope=${installedApp.name};json;norefresh`, axiosOptions).catch((error) => {
log.error(`masterSlaveApps: Failed to reach USA FDM with error: ${error}`);
});
fdmUSAData = fdmUSAData.data;
Expand All @@ -10581,7 +10591,7 @@ async function masterSlaveApps() {
}
if (!ip || !serverStatus) {
// eslint-disable-next-line no-await-in-loop
let fdmASIAData = await serviceHelper.axiosGet(`https://fdm-sg-1-4.runonflux.io/fluxstatistics?scope=${installedApp.name};json;norefresh`, axiosOptions).catch((error) => {
let fdmASIAData = await serviceHelper.axiosGet(`https://fdm-sg-1-${fdmIndex}.runonflux.io/fluxstatistics?scope=${installedApp.name};json;norefresh`, axiosOptions).catch((error) => {
log.error(`masterSlaveApps: Failed to reach ASIA FDM with error: ${error}`);
});
fdmASIAData = fdmASIAData.data;
Expand Down Expand Up @@ -10615,10 +10625,20 @@ async function masterSlaveApps() {
const identifier = `${installedComponent.name}_${installedApp.name}`;
const appId = dockerService.getAppIdentifier(identifier);
if (installedComponent.containerData.includes('g:') && receiveOnlySyncthingAppsCache.get(appId).restarted) {
let fdmIndex = 1;
const appNameFirstLetterLowerCase = installedApp.name.substring(1, 1).toLowerCase();
if (appNameFirstLetterLowerCase.match(/[h-n]/)) {
fdmIndex = 2;
} else if (appNameFirstLetterLowerCase.match(/[o-u]/)) {
fdmIndex = 3;
} else if (appNameFirstLetterLowerCase.match(/[v-z]/)) {
fdmIndex = 4;
}
log.info(`masterSlaveApps: fdmIndex:${fdmIndex}`);
let ip = null;
let serverStatus = null;
// eslint-disable-next-line no-await-in-loop
let fdmEUData = await serviceHelper.axiosGet(`https://fdm-fn-1-4.runonflux.io/fluxstatistics?scope=${installedApp.name};json;norefresh`, axiosOptions).catch((error) => {
let fdmEUData = await serviceHelper.axiosGet(`https://fdm-fn-1-${fdmIndex}.runonflux.io/fluxstatistics?scope=${installedApp.name};json;norefresh`, axiosOptions).catch((error) => {
log.error(`masterSlaveApps: Failed to reach EU FDM with error: ${error}`);
});
fdmEUData = fdmEUData.data;
Expand All @@ -10632,7 +10652,7 @@ async function masterSlaveApps() {
}
if (!ip || !serverStatus) {
// eslint-disable-next-line no-await-in-loop
let fdmUSAData = await serviceHelper.axiosGet(`https://fdm-usa-1-4.runonflux.io/fluxstatistics?scope=${installedApp.name};json;norefresh`, axiosOptions).catch((error) => {
let fdmUSAData = await serviceHelper.axiosGet(`https://fdm-usa-1-${fdmIndex}.runonflux.io/fluxstatistics?scope=${installedApp.name};json;norefresh`, axiosOptions).catch((error) => {
log.error(`masterSlaveApps: Failed to reach USA FDM with error: ${error}`);
});
fdmUSAData = fdmUSAData.data;
Expand All @@ -10647,7 +10667,7 @@ async function masterSlaveApps() {
}
if (!ip || !serverStatus) {
// eslint-disable-next-line no-await-in-loop
let fdmASIAData = await serviceHelper.axiosGet(`https://fdm-sg-1-4.runonflux.io/fluxstatistics?scope=${installedApp.name};json;norefresh`, axiosOptions).catch((error) => {
let fdmASIAData = await serviceHelper.axiosGet(`https://fdm-sg-1-${fdmIndex}.runonflux.io/fluxstatistics?scope=${installedApp.name};json;norefresh`, axiosOptions).catch((error) => {
log.error(`masterSlaveApps: Failed to reach ASIA FDM with error: ${error}`);
});
fdmASIAData = fdmASIAData.data;
Expand Down

0 comments on commit 6ec765d

Please sign in to comment.