summaryrefslogtreecommitdiff
path: root/lib/bridge/index.js
blob: e0ab44124b2348736c47e88d2f15d22d3b9377d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { execFile } from 'child_process'

export default class Bridge {
  constructor() {
    this.cpus = []
    this.getCPUs()
  }
  getCPUs() {
    this.run(['python/devices.py']).then( (stdout, stderr) => {
      this.cpus = JSON.parse(stdout)
      console.log(this.cpus)
    }).catch( (err) => {
      console.error('error fetching cpus:', err)
    })
  }
  run(args) {
    return new Promise( (resolve, reject) => {
      console.log('>', args.join(' '))
      execFile(process.env.PYTHON_BINARY, args, (err, stdout, stderr) => {
        if (err) return reject(err)
        return resolve(stdout, stderr)
      })
    })
  }
}