diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2021-03-27 16:57:05 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2021-03-27 16:57:05 +0300 |
commit | 0327f8962fbf42c4f113cb7f8fbc5f462d2ec13b (patch) | |
tree | b697b5821dbce3798b4abbaa862c2343fab2a197 | |
parent | 832055d922032544439f204198e78e4fe7ca5c45 (diff) |
jobd: support launcher environment settings
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | jobd.conf.example | 2 | ||||
-rw-r--r-- | src/lib/config.js | 10 | ||||
-rw-r--r-- | src/lib/worker.js | 7 |
4 files changed, 22 insertions, 1 deletions
@@ -382,6 +382,10 @@ Without section: in every request - `launcher` *(required, string)* — a template of shell command that will be launched for every job. `{id}` will be replaced with job id +- `launcher.cwd` *(string, default: `process.cwd()`)* — current working directory + for spawned launcher processes +- `launcher.env.{any}` *(string)* — environment variable for spawned launcher + processes - `max_output_buffer` *(int, default: `1048576`)* Under the `[targets]` section, targets are specified. Each target is specified on diff --git a/jobd.conf.example b/jobd.conf.example index 786714d..57e0701 100644 --- a/jobd.conf.example +++ b/jobd.conf.example @@ -24,6 +24,8 @@ mysql_fetch_limit = 10 ; launcher command template launcher = php /Users/ch1p/jobd-launcher.php --id {id} +launcher.cwd = /Users/ch1p +launcher.env.LC_ALL = en_US.UTF-8 max_output_buffer = 16777216 [targets] 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 = [] |