Fix fail fast mechanism.

This commit is contained in:
André Cruz
2013-06-03 16:49:40 +01:00
parent afd01cc40c
commit e188047cfb

View File

@@ -61,7 +61,7 @@ Manager.prototype.resolve = function () {
this._fetching = {};
this._nrFetching = 0;
this._failed = {};
this._failFast = false;
this._hasFailed = false;
this._deferred = Q.defer();
// If there's nothing to resolve, simply dissect
@@ -184,8 +184,8 @@ Manager.prototype._fetch = function (decEndpoint) {
var name = decEndpoint.name;
var logger;
// Check if the whole process is marked to fail fast
if (this._failFast) {
// Check if the whole process started to fail fast
if (this._hasFailed) {
return;
}
@@ -271,7 +271,7 @@ Manager.prototype._onFetchError = function (decEndpoint, err) {
delete decEndpoint.promise;
// Make the whole process to fail fast
this._failFast = true;
this._failFast();
// If the resolve process ended, parse the resolved packages
// to find the most suitable version for each package
@@ -281,11 +281,11 @@ Manager.prototype._onFetchError = function (decEndpoint, err) {
};
Manager.prototype._failFast = function () {
if (this._failFast) {
if (this._failFastTimeout) {
return;
}
this._failFast = true;
this._hasFailed = true;
// If after 20 seconds all pending tasks haven't finished,
// we force the process to end
@@ -295,7 +295,6 @@ Manager.prototype._failFast = function () {
}.bind(this), 20000);
};
Manager.prototype._parseDependencies = function (decEndpoint, pkgMeta) {
// Parse package dependencies
mout.object.forOwn(pkgMeta.dependencies, function (value, key) {
@@ -352,7 +351,7 @@ Manager.prototype._dissect = function () {
// If something failed, reject the whole resolve promise
// with the first error
if (this._failFast) {
if (this._hasFailed) {
clearTimeout(this._failFastTimeout); // Cancel fail fast timeout
err = mout.object.values(this._failed)[0][0];