diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/config.js | 10 | ||||
-rw-r--r-- | src/lib/worker.js | 7 |
2 files changed, 16 insertions, 1 deletions
diff --git a/src/lib/config.js b/src/lib/config.js index 289a79f..f3a9e61 100644 --- a/src/lib/config.js +++ b/src/lib/config.js @@ -49,6 +49,14 @@ function processScheme(source, scheme) { value = !!value } break + + case 'map': + value = {} + for (let key1 in source) { + if (key1.startsWith(`${key}.`)) + value[key1.substring(key.length+1)] = source[key1] + } + break } } @@ -85,6 +93,8 @@ function parseWorkerConfig(file) { mysql_fetch_limit: {default: 100, type: 'int'}, launcher: {required: true}, + 'launcher.cwd': {default: process.cwd()}, + 'launcher.env': {type: 'map', default: {}}, max_output_buffer: {default: 1024*1024, type: 'int'}, targets: {required: true, type: 'object'}, } diff --git a/src/lib/worker.js b/src/lib/worker.js index cd1f0cd..3a4bb83 100644 --- a/src/lib/worker.js +++ b/src/lib/worker.js @@ -468,12 +468,17 @@ class Worker extends EventEmitter { */ async run(id) { let command = config.get('launcher').replace(/\{id\}/g, id) + let cwd = config.get('launcher.cwd') + let env = Object.assign({}, process.env, config.get('launcher.env')) + let args = command.split(/ +/) return new Promise((resolve, reject) => { this.logger.info(`run(${id}): launching`, args) let process = child_process.spawn(args[0], args.slice(1), { - maxBuffer: config.get('max_output_buffer') + maxBuffer: config.get('max_output_buffer'), + cwd, + env }) let stdoutChunks = [] |