diff options
Diffstat (limited to 'lib/bridge')
| -rw-r--r-- | lib/bridge/index.js | 47 | ||||
| -rw-r--r-- | lib/bridge/monitor.js | 19 |
2 files changed, 59 insertions, 7 deletions
diff --git a/lib/bridge/index.js b/lib/bridge/index.js index e0ab441..096c3b9 100644 --- a/lib/bridge/index.js +++ b/lib/bridge/index.js @@ -1,16 +1,16 @@ -import { execFile } from 'child_process' +import { execFile, spawn } from 'child_process' export default class Bridge { constructor() { this.cpus = [] - this.getCPUs() + this.getDevices() } - getCPUs() { + getDevices() { this.run(['python/devices.py']).then( (stdout, stderr) => { - this.cpus = JSON.parse(stdout) - console.log(this.cpus) + this.devices = JSON.parse(stdout) + console.log(this.devices) }).catch( (err) => { - console.error('error fetching cpus:', err) + console.error('error fetching devices:', err) }) } run(args) { @@ -22,4 +22,37 @@ export default class Bridge { }) }) } -}
\ No newline at end of file + monitor(args) { + return new Monitor(args) + } + process(file) { + ipc.server.sockets.forEach( (socket) => { + console.log('>> sending process') + ipc.server.emit(socket, 'process', true) + }) + } +} + +var ipc = require('node-ipc') + +ipc.config.id = 'cortex' +ipc.config.retry = 1500; + +ipc.serve( () => { + ipc.server.on('connect', (socket) => { + console.log('>>> worker connected') + ipc.server.emit(socket, 'message', true) + }) +// ipc.server.on('message', (data, socket) => { +// ipc.log('got a message : '.debug, data); +// ipc.server.emit( +// socket, +// 'message', +// data+' world!' +// ) +// }) +// ipc.server.on( 'socket.disconnected', (socket, destroyedSocketID) => { +// ipc.log('client ' + destroyedSocketID + ' has disconnected!'); +// }) +}) +ipc.server.start() diff --git a/lib/bridge/monitor.js b/lib/bridge/monitor.js new file mode 100644 index 0000000..d8d29ef --- /dev/null +++ b/lib/bridge/monitor.js @@ -0,0 +1,19 @@ +class Monitor { + constructor(args) { + const cmd = spawn(process.env.PYTHON_BINARY, args); + + let stdout = '', stderr = '' + + cmd.stdout.on('data', (data) => { + this.stdout += data + }) + + cmd.stderr.on('data', (data) => { + this.stderr += data + }) + + cmd.on('exit', function (code) { + exit && exit( data.toString() ) + }) + } +} |
