diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2017-07-02 06:29:58 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2017-07-02 06:29:58 +0200 |
| commit | be26f182ccdff4f96c52d419deebee4aff055e18 (patch) | |
| tree | 227399a1a20de01e00d1a524be0c3875a2defcca /lib/bridge/index.js | |
| parent | 22735b5dcb3503b5575d77bb066159f623e60f9e (diff) | |
worker in own process
Diffstat (limited to 'lib/bridge/index.js')
| -rw-r--r-- | lib/bridge/index.js | 47 |
1 files changed, 40 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() |
