Skip to content

Commit

Permalink
options, feat: retry download when http error.
Browse files Browse the repository at this point in the history
  • Loading branch information
xicilion committed Jan 13, 2018
1 parent 3e1bd98 commit 416b7e1
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions fibjs/scripts/opt_tools/install.js
Expand Up @@ -1319,13 +1319,27 @@ function read_module(p, parent) {

var infos = {};

function http_get(u) {
var cnt = 0;

while (cnt < 3)
try {
return http.get(u);
} catch (e) {
console.warn("download error. retry ", u);
}

console.error("download error.", u);
process.exit(-1);
}

function get_version(m, v, parent) {
var info = infos[m];

if (info === undefined) {
var url = snap.registry + m.replace(/\//g, '%2F');
console.log('fetch metadata:', m, "=>", url);
infos[m] = info = http.get(url).json();
infos[m] = info = http_get(url).json();
}

var vers = [];
Expand Down Expand Up @@ -1451,7 +1465,7 @@ function mkdir(p) {
function download_module() {
coroutine.parallel(Object.keys(paths), m => {
m = paths[m];
var r = http.get(m.dist.tarball);
var r = http_get(m.dist.tarball);
if (r.statusCode !== 200) {
console.error('doenload error::', m.dist.tarball);
process.exit();
Expand Down

0 comments on commit 416b7e1

Please sign in to comment.