-
Notifications
You must be signed in to change notification settings - Fork 3
/
runner.js
55 lines (48 loc) · 1.68 KB
/
runner.js
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const wrapper = require.resolve('./controlwrap.js');
const { determineUniquePathName, createDir } = require('../util/utils');
const path = require('path');
const foreground = require('foreground-child');
const sw = require('spawn-wrap');
class Runner {
constructor(hbfile, runs, command, logDir, strategy) {
this.hbfile = hbfile;
this.runs = runs;
this.command = command;
this.origLogDir = logDir;
this.logDir = determineUniquePathName(logDir, 'exec');
this.strategy = strategy;
}
start() {
console.log('Strategy: ' + this.strategy);
console.log('Command: ' + this.command.join(' '));
console.log('Runs: ' + this.runs);
console.log('Log dir: ' + this.logDir);
createDir(this.logDir);
this.memoryPath = path.join(this.origLogDir, 'memory.json');
process.setMaxListeners(0); //remove warning
this.unwrap = null;
this.run(1, this.runs);
}
run(current, times) {
if (current <= times) {
let p = new Promise((resolve, reject) => { // eslint-disable-line no-unused-vars
if (this.unwrap)
this.unwrap();
this.unwrap = sw([wrapper], {
run: current,
logDir: this.logDir,
hbfile: this.hbfile,
strategy: this.strategy,
memory: this.memoryPath
});
foreground(this.command, () => {
resolve();
});
});
p.then(() => {
this.run(current + 1, times);
});
}
}
}
module.exports = Runner;