mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-18 13:53:22 +02:00
add groups feature
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Copyright © 2019 contains code contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0
|
||||
**/
|
||||
|
||||
var http = require('http')
|
||||
var path = require('path')
|
||||
var events = require('events')
|
||||
@@ -51,16 +55,51 @@ module.exports = function(options) {
|
||||
lifecycle.fatal()
|
||||
})
|
||||
|
||||
var pushdev = zmqutil.socket('push')
|
||||
Promise.map(options.endpoints.pushdev, function(endpoint) {
|
||||
return srv.resolve(endpoint).then(function(records) {
|
||||
return srv.attempt(records, function(record) {
|
||||
log.info('Sending output to "%s"', record.url)
|
||||
pushdev.connect(record.url)
|
||||
return Promise.resolve(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
.catch(function(err) {
|
||||
log.fatal('Unable to connect to pushdev endpoint', err)
|
||||
lifecycle.fatal()
|
||||
})
|
||||
|
||||
var subdev = zmqutil.socket('sub')
|
||||
Promise.map(options.endpoints.subdev, function(endpoint) {
|
||||
return srv.resolve(endpoint).then(function(records) {
|
||||
return srv.attempt(records, function(record) {
|
||||
log.info('Receiving input from "%s"', record.url)
|
||||
subdev.connect(record.url)
|
||||
return Promise.resolve(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
.catch(function(err) {
|
||||
log.fatal('Unable to connect to subdev endpoint', err)
|
||||
lifecycle.fatal()
|
||||
})
|
||||
|
||||
// Establish always-on channels
|
||||
;[wireutil.global].forEach(function(channel) {
|
||||
log.info('Subscribing to permanent channel "%s"', channel)
|
||||
sub.subscribe(channel)
|
||||
subdev.subscribe(channel)
|
||||
})
|
||||
|
||||
sub.on('message', function(channel, data) {
|
||||
channelRouter.emit(channel.toString(), channel, data)
|
||||
})
|
||||
|
||||
subdev.on('message', function(channel, data) {
|
||||
channelRouter.emit(channel.toString(), channel, data)
|
||||
})
|
||||
|
||||
// Swagger Express Config
|
||||
var config = {
|
||||
appRoot: __dirname
|
||||
@@ -81,6 +120,8 @@ module.exports = function(options) {
|
||||
push: push
|
||||
, sub: sub
|
||||
, channelRouter: channelRouter
|
||||
, pushdev: pushdev
|
||||
, subdev: subdev
|
||||
})
|
||||
|
||||
req.options = reqOptions
|
||||
@@ -94,7 +135,7 @@ module.exports = function(options) {
|
||||
}))
|
||||
|
||||
lifecycle.observe(function() {
|
||||
[push, sub].forEach(function(sock) {
|
||||
[push, sub, pushdev, subdev].forEach(function(sock) {
|
||||
try {
|
||||
sock.close()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user