🐎 Switch to master source if CDN too slow

This commit is contained in:
C-3PO 2018-11-16 17:28:01 +01:00
parent cad71700b5
commit f6298af4c4
Signed by: c3po
GPG key ID: 62993C4BB4D86F24
3 changed files with 10 additions and 4 deletions

View file

@ -1,5 +1,6 @@
import * as os from 'os'; import * as os from 'os';
import * as nodePath from 'path'; import * as nodePath from 'path';
import patchMasterSource from '../interfaces/PatchMasterSource';
import downloadWithCurl from './downloadWithCurl'; import downloadWithCurl from './downloadWithCurl';
import checkLocalCache from './funcs/checkLocalCache'; import checkLocalCache from './funcs/checkLocalCache';
import createDirRecursively from './funcs/createDirRecursively'; import createDirRecursively from './funcs/createDirRecursively';
@ -21,10 +22,12 @@ export default async function downloadWrapper({ host, path, size }: {host: strin
} }
//Download via curl //Download via curl
//Try up to ten times //Try up to 15 times
for (let i = 0; i < 10; i += 1) { for (let i = 0; i < 15; i += 1) {
try { try {
const downloadResult = await downloadWithCurl({ host, path, tempFileName }); //After five tries from CDN, switch to master source
const currentHost = (host === 'cdn-patch.swtor.com' && i >= 5 ? patchMasterSource : host);
const downloadResult = await downloadWithCurl({ host: currentHost, path, tempFileName });
return downloadResult; return downloadResult;
} catch (err) { } catch (err) {
console.error(err); console.error(err);

View file

@ -1,4 +1,5 @@
import { IServerEntry } from '../interfaces/IDnsResult'; import { IServerEntry } from '../interfaces/IDnsResult';
import patchMasterSource from '../interfaces/PatchMasterSource';
import resolveDns from './funcs/resolveDns'; import resolveDns from './funcs/resolveDns';
/** Time when this script started, for delta time calculations */ /** Time when this script started, for delta time calculations */
@ -8,7 +9,7 @@ let lastUpdate = 0;
/** List of servers, sorted by reliability */ /** List of servers, sorted by reliability */
let servers: IServerEntry[] = []; let servers: IServerEntry[] = [];
//the master source is included by default //the master source is included by default
servers.push({ ip: '159.153.92.51', type: 'master', lastSeen: Infinity, weight: Infinity }); servers.push({ ip: patchMasterSource, type: 'master', lastSeen: Infinity, weight: Infinity });
/** Updates the list of servers based on current DNS data */ /** Updates the list of servers based on current DNS data */
async function heartbeatDns(domain: string) { async function heartbeatDns(domain: string) {

View file

@ -0,0 +1,2 @@
/** The master server hosting the patch files. */
export default '159.153.92.51';