mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-12 03:47:50 +00:00
Fix restarting tunnels.
This commit is contained in:
@@ -516,8 +516,8 @@ Job.prototype.stop = function(callback) {
|
|||||||
if (this.statusId) {
|
if (this.statusId) {
|
||||||
this.statusId = clearTimeout(this.statusId);
|
this.statusId = clearTimeout(this.statusId);
|
||||||
}
|
}
|
||||||
if (this.id == null) {
|
if (this.id == null || !this.running) {
|
||||||
_.defer(_.bind(this.emit, this, 'stop'));
|
_.defer(_.bind(onJobStop, this));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
request.put(_.template('https://saucelabs.com/rest/v1/${user}/jobs/${id}/stop', this), {
|
request.put(_.template('https://saucelabs.com/rest/v1/${user}/jobs/${id}/stop', this), {
|
||||||
@@ -541,11 +541,15 @@ function Tunnel(properties) {
|
|||||||
this.retries = maxTunnelRetries;
|
this.retries = maxTunnelRetries;
|
||||||
_.merge(this, properties);
|
_.merge(this, properties);
|
||||||
|
|
||||||
this.connection = new SauceTunnel(this.user, this.pass, this.id, this.tunneled, this.timeout);
|
this.attempts = 0;
|
||||||
|
this.running = false;
|
||||||
|
this.starting = false;
|
||||||
|
this.stopping = false;
|
||||||
|
|
||||||
this.jobs = { 'active': [], 'queue': [] };
|
var active = [],
|
||||||
|
queue = [];
|
||||||
|
|
||||||
this.jobs.all = _.map(this.platforms, function(platform) {
|
var all = _.map(this.platforms, function(platform) {
|
||||||
return new Job(_.merge({
|
return new Job(_.merge({
|
||||||
'user': this.user,
|
'user': this.user,
|
||||||
'pass': this.pass,
|
'pass': this.pass,
|
||||||
@@ -554,10 +558,31 @@ function Tunnel(properties) {
|
|||||||
}, this.job));
|
}, this.job));
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
this.attempts = 0;
|
var completed = 0,
|
||||||
this.running = false;
|
success = true,
|
||||||
this.starting = false;
|
total = all.length,
|
||||||
this.stopping = false;
|
tunnel = this;
|
||||||
|
|
||||||
|
_.invoke(all, 'on', 'complete', function() {
|
||||||
|
_.pull(active, this);
|
||||||
|
if (success) {
|
||||||
|
success = !this.failed;
|
||||||
|
}
|
||||||
|
if (++completed == total) {
|
||||||
|
tunnel.running = false;
|
||||||
|
tunnel.emit('complete', success);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
tunnel.dequeue();
|
||||||
|
});
|
||||||
|
|
||||||
|
this.on('stop', function() {
|
||||||
|
completed = 0;
|
||||||
|
success = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.jobs = {'active': active, 'all': all, 'queue': queue };
|
||||||
|
this.connection = new SauceTunnel(this.user, this.pass, this.id, this.tunneled, this.timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
Tunnel.prototype = _.create(EventEmitter.prototype);
|
Tunnel.prototype = _.create(EventEmitter.prototype);
|
||||||
@@ -594,9 +619,7 @@ Tunnel.prototype.start = function(callback) {
|
|||||||
this.starting = true;
|
this.starting = true;
|
||||||
|
|
||||||
this.connection.start(function(success) {
|
this.connection.start(function(success) {
|
||||||
tunnel.running = true;
|
|
||||||
tunnel.starting = false;
|
tunnel.starting = false;
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
if (tunnel.attempts < tunnel.retries) {
|
if (tunnel.attempts < tunnel.retries) {
|
||||||
tunnel.restart();
|
tunnel.restart();
|
||||||
@@ -607,30 +630,12 @@ Tunnel.prototype.start = function(callback) {
|
|||||||
}
|
}
|
||||||
console.log('Sauce Connect tunnel opened');
|
console.log('Sauce Connect tunnel opened');
|
||||||
|
|
||||||
var jobs = tunnel.jobs,
|
var jobs = tunnel.jobs;
|
||||||
queue = jobs.queue,
|
push.apply(jobs.queue, jobs.all);
|
||||||
active = jobs.active;
|
|
||||||
|
|
||||||
push.apply(queue, jobs.all);
|
|
||||||
|
|
||||||
var completed = 0,
|
|
||||||
total = queue.length;
|
|
||||||
|
|
||||||
|
tunnel.running = true;
|
||||||
tunnel.emit('start');
|
tunnel.emit('start');
|
||||||
|
|
||||||
_.invoke(queue, 'on', 'complete', function() {
|
|
||||||
_.pull(active, this);
|
|
||||||
if (success) {
|
|
||||||
success = !this.failed;
|
|
||||||
}
|
|
||||||
if (++completed == total) {
|
|
||||||
tunnel.running = false;
|
|
||||||
tunnel.emit('complete', success);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
tunnel.dequeue();
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log('Starting jobs...');
|
console.log('Starting jobs...');
|
||||||
tunnel.dequeue();
|
tunnel.dequeue();
|
||||||
});
|
});
|
||||||
@@ -686,7 +691,7 @@ Tunnel.prototype.stop = function(callback) {
|
|||||||
this.stopping = true;
|
this.stopping = true;
|
||||||
queue.length = 0;
|
queue.length = 0;
|
||||||
|
|
||||||
if (!total) {
|
if (!total || !this.running) {
|
||||||
_.defer(onTunnelStop);
|
_.defer(onTunnelStop);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user