🐎 Switch to master source if CDN too slow
This commit is contained in:
parent
cad71700b5
commit
f6298af4c4
3 changed files with 10 additions and 4 deletions
|
@ -1,5 +1,6 @@
|
|||
import * as os from 'os';
|
||||
import * as nodePath from 'path';
|
||||
import patchMasterSource from '../interfaces/PatchMasterSource';
|
||||
import downloadWithCurl from './downloadWithCurl';
|
||||
import checkLocalCache from './funcs/checkLocalCache';
|
||||
import createDirRecursively from './funcs/createDirRecursively';
|
||||
|
@ -21,10 +22,12 @@ export default async function downloadWrapper({ host, path, size }: {host: strin
|
|||
}
|
||||
|
||||
//Download via curl
|
||||
//Try up to ten times
|
||||
for (let i = 0; i < 10; i += 1) {
|
||||
//Try up to 15 times
|
||||
for (let i = 0; i < 15; i += 1) {
|
||||
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;
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { IServerEntry } from '../interfaces/IDnsResult';
|
||||
import patchMasterSource from '../interfaces/PatchMasterSource';
|
||||
import resolveDns from './funcs/resolveDns';
|
||||
|
||||
/** Time when this script started, for delta time calculations */
|
||||
|
@ -8,7 +9,7 @@ let lastUpdate = 0;
|
|||
/** List of servers, sorted by reliability */
|
||||
let servers: IServerEntry[] = [];
|
||||
//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 */
|
||||
async function heartbeatDns(domain: string) {
|
||||
|
|
2
src/interfaces/PatchMasterSource.ts
Normal file
2
src/interfaces/PatchMasterSource.ts
Normal file
|
@ -0,0 +1,2 @@
|
|||
/** The master server hosting the patch files. */
|
||||
export default '159.153.92.51';
|
Loading…
Reference in a new issue