mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-19 01:53:27 +02:00
Move support plugins to their own folder.
This commit is contained in:
25
lib/roles/device/support/adb.js
Normal file
25
lib/roles/device/support/adb.js
Normal file
@@ -0,0 +1,25 @@
|
||||
var syrup = require('syrup')
|
||||
|
||||
var adbkit = require('adbkit')
|
||||
|
||||
var logger = require('../../../util/logger')
|
||||
var promiseutil = require('../../../util/promiseutil')
|
||||
|
||||
module.exports = syrup()
|
||||
.define(function(options) {
|
||||
var log = logger.createLogger('device:plugins:adb')
|
||||
var adb = adbkit.createClient()
|
||||
|
||||
function ensureBootComplete() {
|
||||
return promiseutil.periodicNotify(
|
||||
adb.waitBootComplete(options.serial)
|
||||
, 1000
|
||||
)
|
||||
.progressed(function() {
|
||||
log.info('Waiting for boot to complete')
|
||||
})
|
||||
}
|
||||
|
||||
return ensureBootComplete()
|
||||
.return(adb)
|
||||
})
|
||||
14
lib/roles/device/support/channels.js
Normal file
14
lib/roles/device/support/channels.js
Normal file
@@ -0,0 +1,14 @@
|
||||
var syrup = require('syrup')
|
||||
|
||||
var logger = require('../../../util/logger')
|
||||
var ChannelManager = require('../../../wire/channelmanager')
|
||||
|
||||
module.exports = syrup()
|
||||
.define(function(options, router) {
|
||||
var log = logger.createLogger('device:plugins:channels')
|
||||
var channels = new ChannelManager()
|
||||
channels.on('timeout', function(channel) {
|
||||
log.info('Channel "%s" timed out', channel)
|
||||
})
|
||||
return channels
|
||||
})
|
||||
19
lib/roles/device/support/push.js
Normal file
19
lib/roles/device/support/push.js
Normal file
@@ -0,0 +1,19 @@
|
||||
var syrup = require('syrup')
|
||||
|
||||
var zmq = require('zmq')
|
||||
|
||||
var logger = require('../../../util/logger')
|
||||
|
||||
module.exports = syrup()
|
||||
.define(function(options) {
|
||||
var log = logger.createLogger('device:plugins:push')
|
||||
|
||||
// Output
|
||||
var push = zmq.socket('push')
|
||||
options.endpoints.push.forEach(function(endpoint) {
|
||||
log.info('Sending output to %s', endpoint)
|
||||
push.connect(endpoint)
|
||||
})
|
||||
|
||||
return push
|
||||
})
|
||||
38
lib/roles/device/support/quit.js
Normal file
38
lib/roles/device/support/quit.js
Normal file
@@ -0,0 +1,38 @@
|
||||
var Promise = require('bluebird')
|
||||
var syrup = require('syrup')
|
||||
|
||||
var logger = require('../../../util/logger')
|
||||
|
||||
module.exports = syrup()
|
||||
.define(function(options) {
|
||||
var log = logger.createLogger('device:plugins:quit')
|
||||
var cleanup = []
|
||||
|
||||
function graceful() {
|
||||
log.info('Winding down for graceful exit')
|
||||
|
||||
var wait = Promise.all(cleanup.map(function(fn) {
|
||||
return fn()
|
||||
}))
|
||||
|
||||
return wait.then(function() {
|
||||
process.exit(0)
|
||||
})
|
||||
}
|
||||
|
||||
function fatal() {
|
||||
log.fatal('Shutting down due to fatal error')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
process.on('SIGINT', graceful)
|
||||
process.on('SIGTERM', graceful)
|
||||
|
||||
return {
|
||||
graceful: graceful
|
||||
, fatal: fatal
|
||||
, observe: function(promise) {
|
||||
cleanup.push(promise)
|
||||
}
|
||||
}
|
||||
})
|
||||
15
lib/roles/device/support/router.js
Normal file
15
lib/roles/device/support/router.js
Normal file
@@ -0,0 +1,15 @@
|
||||
var syrup = require('syrup')
|
||||
|
||||
var wirerouter = require('../../../wire/router')
|
||||
|
||||
module.exports = syrup()
|
||||
.dependency(require('./sub'))
|
||||
.dependency(require('./channels'))
|
||||
.define(function(options, sub, channels) {
|
||||
var router = wirerouter()
|
||||
sub.on('message', router.handler())
|
||||
router.on('message', function(channel) {
|
||||
channels.keepalive(channel)
|
||||
})
|
||||
return router
|
||||
})
|
||||
28
lib/roles/device/support/sub.js
Normal file
28
lib/roles/device/support/sub.js
Normal file
@@ -0,0 +1,28 @@
|
||||
var syrup = require('syrup')
|
||||
|
||||
var zmq = require('zmq')
|
||||
|
||||
var logger = require('../../../util/logger')
|
||||
var wireutil = require('../../../wire/util')
|
||||
|
||||
module.exports = syrup()
|
||||
.dependency(require('./channels'))
|
||||
.define(function(options, channels) {
|
||||
var log = logger.createLogger('device:plugins:sub')
|
||||
|
||||
// Input
|
||||
var sub = zmq.socket('sub')
|
||||
options.endpoints.sub.forEach(function(endpoint) {
|
||||
log.info('Receiving input from %s', endpoint)
|
||||
sub.connect(endpoint)
|
||||
})
|
||||
|
||||
// Establish always-on channels
|
||||
;[wireutil.global].forEach(function(channel) {
|
||||
log.info('Subscribing to permanent channel "%s"', channel)
|
||||
sub.subscribe(channel)
|
||||
channels.register(channel, Infinity)
|
||||
})
|
||||
|
||||
return sub
|
||||
})
|
||||
Reference in New Issue
Block a user