mirror of
https://github.com/openstf/stf
synced 2025-10-04 10:19:30 +02:00
Allocate two ports to each worker.
This commit is contained in:
parent
e0426d01be
commit
c45c081c6f
3 changed files with 43 additions and 12 deletions
|
@ -93,7 +93,8 @@ module.exports = function(options) {
|
|||
function maybeConnect(device) {
|
||||
if (isConnectable(device) && !isConnected(device)) {
|
||||
log.info('Spawning device worker "%s"', device.id)
|
||||
var proc = options.fork(device)
|
||||
var ports = options.ports.splice(0, 2)
|
||||
, proc = options.fork(device, ports)
|
||||
|
||||
function errorListener(err) {
|
||||
log.error('Device worker "%s" had an error: %s',
|
||||
|
@ -101,9 +102,7 @@ module.exports = function(options) {
|
|||
}
|
||||
|
||||
function exitListener(code, signal) {
|
||||
var data = workers[device.id]
|
||||
delete workers[device.id]
|
||||
counter -= 1
|
||||
var worker = cleanupWorker(device.id)
|
||||
switch (code) {
|
||||
case 0:
|
||||
log.info('Device worker "%s" stopped cleanly', device.id)
|
||||
|
@ -113,7 +112,7 @@ module.exports = function(options) {
|
|||
, device.id)
|
||||
break
|
||||
default:
|
||||
if (Date.now() - data.started < options.restartThreshold) {
|
||||
if (Date.now() - worker.started < options.restartThreshold) {
|
||||
log.error(
|
||||
'Device worker "%s" died with exit code %d, ' +
|
||||
'NOT restarting due to threshold of %dms not being met'
|
||||
|
@ -157,6 +156,7 @@ module.exports = function(options) {
|
|||
device: device
|
||||
, proc: proc
|
||||
, started: Date.now()
|
||||
, ports: ports
|
||||
, unbind: function() {
|
||||
proc.removeListener('error', errorListener)
|
||||
proc.removeListener('exit', exitListener)
|
||||
|
@ -204,10 +204,8 @@ module.exports = function(options) {
|
|||
worker = workers[id]
|
||||
|
||||
function onExit() {
|
||||
delete workers[id]
|
||||
cleanupWorker(id)
|
||||
log.info('Gracefully killed device worker "%s"', id)
|
||||
counter -= 1
|
||||
boast()
|
||||
deferred.resolve()
|
||||
}
|
||||
|
||||
|
@ -227,10 +225,8 @@ module.exports = function(options) {
|
|||
, worker = workers[id]
|
||||
|
||||
function onExit() {
|
||||
delete workers[id]
|
||||
cleanupWorker(id)
|
||||
log.warn('Force killed device worker "%s"', id)
|
||||
counter -= 1
|
||||
boast()
|
||||
deferred.resolve()
|
||||
}
|
||||
|
||||
|
@ -262,6 +258,15 @@ module.exports = function(options) {
|
|||
})
|
||||
}
|
||||
|
||||
function cleanupWorker(id) {
|
||||
var worker = workers[id]
|
||||
delete workers[id]
|
||||
Array.prototype.push.apply(options.ports, worker.ports)
|
||||
counter -= 1
|
||||
boast()
|
||||
return worker
|
||||
}
|
||||
|
||||
function boast() {
|
||||
log.info('Providing %d device(s)', counter)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue