mirror of
https://github.com/whyour/qinglong.git
synced 2025-12-15 16:35:39 +08:00
Fix NODE_OPTIONS not being available in task_before commands
Export NODE_OPTIONS and PYTHONPATH in bash subprocess so that any node/python commands in task_before (pre-execution field) can access the QLAPI preload. This fixes the issue where running "node /ql/data/scripts/ql_sample.js" in pre-execution fails with "ReferenceError: QLAPI is not defined". Co-authored-by: whyour <22700758+whyour@users.noreply.github.com>
This commit is contained in:
parent
eab8a93f28
commit
ee7d39f433
|
|
@ -28,6 +28,7 @@ function run() {
|
||||||
numParam,
|
numParam,
|
||||||
file_task_before,
|
file_task_before,
|
||||||
file_task_before_js,
|
file_task_before_js,
|
||||||
|
file_preload_js,
|
||||||
dir_scripts,
|
dir_scripts,
|
||||||
task_before,
|
task_before,
|
||||||
PREV_NODE_OPTIONS,
|
PREV_NODE_OPTIONS,
|
||||||
|
|
@ -40,7 +41,13 @@ function run() {
|
||||||
const fileName = process.argv[1].replace(`${dir_scripts}/`, '');
|
const fileName = process.argv[1].replace(`${dir_scripts}/`, '');
|
||||||
const tempFile = `/tmp/env_${process.pid}.json`;
|
const tempFile = `/tmp/env_${process.pid}.json`;
|
||||||
|
|
||||||
|
// Export NODE_OPTIONS so task_before can use it for any node commands
|
||||||
|
const nodeOptionsForBash = file_preload_js
|
||||||
|
? `-r ${file_preload_js} ${PREV_NODE_OPTIONS || ''}`
|
||||||
|
: PREV_NODE_OPTIONS || '';
|
||||||
|
|
||||||
const commands = [
|
const commands = [
|
||||||
|
`export NODE_OPTIONS="${nodeOptionsForBash}"`,
|
||||||
`source ${file_task_before} ${fileName}`,
|
`source ${file_task_before} ${fileName}`,
|
||||||
task_before ? `eval '${task_before.replace(/'/g, "'\\''")}'` : null,
|
task_before ? `eval '${task_before.replace(/'/g, "'\\''")}'` : null,
|
||||||
`echo -e '${splitStr}'`,
|
`echo -e '${splitStr}'`,
|
||||||
|
|
|
||||||
|
|
@ -44,11 +44,19 @@ def run():
|
||||||
split_str = "__sitecustomize__"
|
split_str = "__sitecustomize__"
|
||||||
file_name = sys.argv[0].replace(f"{os.getenv('dir_scripts')}/", "")
|
file_name = sys.argv[0].replace(f"{os.getenv('dir_scripts')}/", "")
|
||||||
|
|
||||||
|
# Get environment variables needed for PYTHONPATH
|
||||||
|
dir_preload = os.getenv("dir_preload", "")
|
||||||
|
dir_config = os.getenv("dir_config", "")
|
||||||
|
|
||||||
# 创建临时文件路径
|
# 创建临时文件路径
|
||||||
temp_file = f"/tmp/env_{os.getpid()}.json"
|
temp_file = f"/tmp/env_{os.getpid()}.json"
|
||||||
|
|
||||||
|
# Export PYTHONPATH so task_before can use it for any python commands
|
||||||
|
pythonpath_for_bash = f"{dir_preload}:{dir_config}:{prev_pythonpath}" if dir_preload else prev_pythonpath
|
||||||
|
|
||||||
# 构建命令数组
|
# 构建命令数组
|
||||||
commands = [
|
commands = [
|
||||||
|
f'export PYTHONPATH="{pythonpath_for_bash}"',
|
||||||
f'source {os.getenv("file_task_before")} {file_name}'
|
f'source {os.getenv("file_task_before")} {file_name}'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user