mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-12 11:57:49 +00:00
Add Job#resetting flag.
This commit is contained in:
@@ -328,6 +328,18 @@ function onJobRemove(error, res, body) {
|
|||||||
this.emit('remove');
|
this.emit('remove');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The `Job#remove` callback used by `Jobs#reset`.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
function onJobReset() {
|
||||||
|
this.attempts = 0;
|
||||||
|
this.failed = this.resetting = false;
|
||||||
|
this._timerId = this.id = this.result = this.testId = this.url = null;
|
||||||
|
this.emit('reset');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The `request.post` callback used by `Jobs#start`.
|
* The `request.post` callback used by `Jobs#start`.
|
||||||
*
|
*
|
||||||
@@ -481,7 +493,7 @@ function Job(properties) {
|
|||||||
_.defaults(this.options, _.cloneDeep(jobOptions));
|
_.defaults(this.options, _.cloneDeep(jobOptions));
|
||||||
|
|
||||||
this.attempts = 0;
|
this.attempts = 0;
|
||||||
this.checking = this.failed = this.removing = this.restarting = this.running = this.starting = this.stopping = false;
|
this.checking = this.failed = this.removing = this.resetting = this.restarting = this.running = this.starting = this.stopping = false;
|
||||||
this._timerId = this.id = this.result = this.testId = this.url = null;
|
this._timerId = this.id = this.result = this.testId = this.url = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -495,25 +507,22 @@ util.inherits(Job, EventEmitter);
|
|||||||
* @param {Object} Returns the job instance.
|
* @param {Object} Returns the job instance.
|
||||||
*/
|
*/
|
||||||
Job.prototype.remove = function(callback) {
|
Job.prototype.remove = function(callback) {
|
||||||
if (this.running) {
|
|
||||||
return this.stop(_.partial(this.remove, callback));
|
|
||||||
}
|
|
||||||
this.once('remove', _.callback(callback));
|
this.once('remove', _.callback(callback));
|
||||||
if (this.removing) {
|
if (this.removing) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
var onRemove = _.bind(onJobRemove, this);
|
|
||||||
|
|
||||||
this.removing = true;
|
this.removing = true;
|
||||||
if (this.id == null) {
|
|
||||||
_.defer(onRemove);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
request.del(_.template('https://saucelabs.com/rest/v1/${user}/jobs/${id}', this), {
|
|
||||||
'auth': { 'user': this.user, 'pass': this.pass }
|
|
||||||
}, onRemove);
|
|
||||||
|
|
||||||
return this;
|
var onRemove = _.bind(onJobRemove, this);
|
||||||
|
return this.stop(function() {
|
||||||
|
if (this.id == null) {
|
||||||
|
onRemove();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
request.del(_.template('https://saucelabs.com/rest/v1/${user}/jobs/${id}', this), {
|
||||||
|
'auth': { 'user': this.user, 'pass': this.pass }
|
||||||
|
}, onRemove);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -524,17 +533,12 @@ Job.prototype.remove = function(callback) {
|
|||||||
* @param {Object} Returns the job instance.
|
* @param {Object} Returns the job instance.
|
||||||
*/
|
*/
|
||||||
Job.prototype.reset = function(callback) {
|
Job.prototype.reset = function(callback) {
|
||||||
if (this.id != null) {
|
|
||||||
return this.remove(_.partial(this.reset, callback));
|
|
||||||
}
|
|
||||||
this.attempts = 0;
|
|
||||||
this.failed = false;
|
|
||||||
this._timerId = this.id = this.result = this.testId = this.url = null;
|
|
||||||
|
|
||||||
this.once('reset', _.callback(callback));
|
this.once('reset', _.callback(callback));
|
||||||
_.defer(_.bind(this.emit, this, 'reset'));
|
if (this.resetting) {
|
||||||
|
return this;
|
||||||
return this;
|
}
|
||||||
|
this.resetting = true;
|
||||||
|
return this.remove(onJobReset);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -592,7 +596,7 @@ Job.prototype.start = function(callback) {
|
|||||||
*/
|
*/
|
||||||
Job.prototype.status = function(callback) {
|
Job.prototype.status = function(callback) {
|
||||||
this.once('status', _.callback(callback));
|
this.once('status', _.callback(callback));
|
||||||
if (this.checking || this.removing || this.restarting || this.starting || this.stopping) {
|
if (this.checking || this.removing || this.resetting || this.restarting || this.starting || this.stopping) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
this.checking = true;
|
this.checking = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user