meteorite-crappy-network-fix
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -11,3 +11,3 @@ var _ = require('underscore'); | ||
var ROLLING_TIMEOUT = 15000; | ||
var FETCH_TRY_COUNT = 3; | ||
var TRY_COUNT = 3; | ||
@@ -48,36 +48,2 @@ GitSource = function(basePath, config) { | ||
GitSource.prototype._downloadFromGit = function (fn, attempt) { | ||
attempt = attempt || 0; | ||
var self = this; | ||
try { | ||
self._clone(function() { | ||
self._pull(function() { | ||
self._checkout(function() { | ||
self._updateSubmodules(function() { | ||
self._commit(function() { | ||
self.path = self.packagePath(); | ||
self._load(function() { | ||
self.loaded = true; | ||
fn(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} catch (e) { | ||
console.log(attempt); | ||
if (attempt < FETCH_TRY_COUNT) { | ||
console.log(('Attempt ' + (attempt + 1) + ' failed, message: ' + e.toString()).yellow); | ||
this._downloadFromGit(fn, attempt + 1); | ||
} else { | ||
console.log('All attempts failed giving up'.red); | ||
throw e; | ||
} | ||
} | ||
}; | ||
GitSource.prototype.fetch = function(fn, name) { | ||
@@ -112,3 +78,17 @@ var self = this; | ||
this._downloadFromGit(fn); | ||
self._clone(function() { | ||
self._pull(function() { | ||
self._checkout(function() { | ||
self._updateSubmodules(function() { | ||
self._commit(function() { | ||
self.path = self.packagePath(); | ||
self._load(function() { | ||
self.loaded = true; | ||
fn(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}; | ||
@@ -135,3 +115,3 @@ | ||
GitSource.prototype._clone = function(fn) { | ||
GitSource.prototype._clone = function(fn, attempt) { | ||
var self = this, | ||
@@ -142,10 +122,18 @@ child, | ||
this.url + ' "' + this.sourcePath + '"', | ||
options = { rollingTimeout: ROLLING_TIMEOUT }; | ||
options = { rollingTimeout: ROLLING_TIMEOUT } | ||
; | ||
attempt = attempt || 0; | ||
if (!fs.existsSync(this.sourcePath)) { | ||
child = exec(command, options, function(err, stdout, stderr) { | ||
if (err) { | ||
reportErrors(err, stdout, stderr, timedOut); | ||
throw "There was a problem cloning repo: " + self.url + | ||
"\nPlease check https://github.com/oortcloud/meteorite/blob/master/CONTRIBUTING.md#troubleshooting for potential explanations."; | ||
if (attempt < TRY_COUNT) { | ||
console.log('Clone attempt ' + attempt + ' failed, retrying') | ||
self._clone(fn, attempt+1); | ||
} else { | ||
reportErrors(err, stdout, stderr, timedOut); | ||
throw "There was a problem cloning repo: " + self.url + | ||
"\nPlease check https://github.com/oortcloud/meteorite/blob/master/CONTRIBUTING.md#troubleshooting for potential explanations."; | ||
} | ||
} | ||
@@ -192,3 +180,3 @@ fn(); | ||
GitSource.prototype._checkout = function(fn) { | ||
GitSource.prototype._checkout = function(fn, attempt) { | ||
var self = this, | ||
@@ -203,7 +191,15 @@ child, | ||
attempt = attempt || 0; | ||
child = exec(command, options, function(err, stdout, stderr) { | ||
if (err) { | ||
reportErrors(err, stdout, stderr, timedOut); | ||
throw "There was a problem checking out " + | ||
if (attempt < TRY_COUNT) { | ||
console.log('Checkout attempt ' + attempt + ' failed, retrying') | ||
self._checkout(fn, attempt+1); | ||
} else { | ||
reportErrors(err, stdout, stderr, timedOut); | ||
throw "There was a problem checking out " + | ||
self.checkoutType + ": " + (self.commit || self.head); | ||
} | ||
} | ||
@@ -275,3 +271,3 @@ fn(); | ||
GitSource.getCommitForDir = function(path, fn) { | ||
GitSource.getCommitForDir = function(path, fn, attempt) { | ||
var self = this, | ||
@@ -286,6 +282,14 @@ child, | ||
attempt = attempt || 0; | ||
child = exec(command, options, function (err, stdout, stderr) { | ||
if (err) { | ||
reportErrors(err, stdout, stderr, timedOut); | ||
throw "Command exited: " + err; | ||
if (attempt < TRY_COUNT) { | ||
console.log('getCommitForDir attempt ' + attempt + ' failed, retrying') | ||
self.getCommitForDir(fn, attempt+1); | ||
} else { | ||
reportErrors(err, stdout, stderr, timedOut); | ||
throw "Command exited: " + err; | ||
} | ||
} | ||
@@ -292,0 +296,0 @@ fn(stdout.trim()); |
{ "name": "meteorite-crappy-network-fix" | ||
, "version": "0.0.4" | ||
, "version": "0.0.5" | ||
, "homepage": "http://oortcloud.github.com/meteorite" | ||
@@ -4,0 +4,0 @@ , "engines": [ "node >=0.8.0" ] |
Sorry, the diff of this file is not supported yet
120649
2010