mirror of
https://github.com/whyour/qinglong.git
synced 2026-07-01 04:40:38 +08:00
增加 task_before.js 和 task_before.py 文件,在执行任务前执行,避免环境变量过大报错
This commit is contained in:
@@ -25,12 +25,23 @@ function expandRange(rangeStr, max) {
|
||||
}
|
||||
|
||||
function run() {
|
||||
const {
|
||||
envParam,
|
||||
numParam,
|
||||
file_task_before,
|
||||
file_task_before_js,
|
||||
dir_scripts,
|
||||
task_before,
|
||||
} = process.env;
|
||||
|
||||
require(file_task_before_js);
|
||||
|
||||
try {
|
||||
// TODO: big size
|
||||
const splitStr = '__sitecustomize__';
|
||||
let command = `bash -c "source ${process.env.taskBefore} ${process.env.fileName}`;
|
||||
if (process.env.task_before) {
|
||||
command = `${command} && echo -e '执行前置命令\n' && eval "${process.env.task_before}" && echo -e '\n执行前置命令结束\n'`;
|
||||
const fileName = process.argv[1].replace(`${dir_scripts}/`, '');
|
||||
let command = `bash -c "source ${file_task_before} ${fileName}`;
|
||||
if (task_before) {
|
||||
command = `${command} && echo -e '执行前置命令\n' && eval "${task_before}" && echo -e '\n执行前置命令结束\n'`;
|
||||
}
|
||||
const res = execSync(
|
||||
`${command} && echo "${splitStr}" && NODE_OPTIONS= node -p 'JSON.stringify(process.env)'"`,
|
||||
@@ -45,10 +56,11 @@ function run() {
|
||||
}
|
||||
console.log(output);
|
||||
} catch (error) {
|
||||
console.log(`run task before error: `, error.message);
|
||||
if (!error.message.includes('spawnSync /bin/sh E2BIG')) {
|
||||
console.log(`run task before error: `, error);
|
||||
}
|
||||
}
|
||||
|
||||
const { envParam, numParam } = process.env;
|
||||
if (envParam && numParam) {
|
||||
const array = (process.env[envParam] || '').split('&');
|
||||
const runArr = expandRange(numParam, array.length);
|
||||
@@ -58,5 +70,9 @@ function run() {
|
||||
}
|
||||
}
|
||||
|
||||
initGlobal();
|
||||
run();
|
||||
try {
|
||||
initGlobal();
|
||||
run();
|
||||
} catch (error) {
|
||||
console.log(`run builtin code error: `, error, '\n');
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import os
|
||||
import re
|
||||
import env
|
||||
import subprocess
|
||||
import json
|
||||
import builtins
|
||||
import sys
|
||||
import env
|
||||
from notify import send
|
||||
|
||||
|
||||
@@ -44,12 +45,16 @@ def expand_range(range_str, max_value):
|
||||
|
||||
|
||||
def run():
|
||||
import task_before
|
||||
|
||||
try:
|
||||
split_str = "__sitecustomize__"
|
||||
command = f'bash -c "source {os.getenv("taskBefore")} {os.getenv("fileName")}'
|
||||
file_name = sys.argv[0].replace(f"{os.getenv('dir_scripts')}/", "")
|
||||
command = f'bash -c "source {os.getenv("file_task_before")} {file_name}'
|
||||
task_before = os.getenv("task_before")
|
||||
|
||||
if os.getenv("task_before"):
|
||||
command += f" && echo -e '执行前置命令\n' && eval \"{os.getenv('task_before')}\" && echo -e '\n执行前置命令结束\n'"
|
||||
if task_before:
|
||||
command += f" && echo -e '执行前置命令\n' && eval \"{task_before}\" && echo -e '\n执行前置命令结束\n'"
|
||||
|
||||
python_command = "PYTHONPATH= python3 -c 'import os, json; print(json.dumps(dict(os.environ)))'"
|
||||
command += f' && echo "{split_str}" && {python_command}"'
|
||||
@@ -66,6 +71,12 @@ def run():
|
||||
|
||||
except subprocess.CalledProcessError as error:
|
||||
print(f"run task before error: {error}")
|
||||
except OSError as error:
|
||||
error_message = str(error)
|
||||
if "Argument list too long" not in error_message:
|
||||
print(f"run task before error: {error}")
|
||||
except Exception as error:
|
||||
print(f"run task before error: {error}")
|
||||
|
||||
env_param = os.getenv("envParam")
|
||||
num_param = os.getenv("numParam")
|
||||
@@ -78,5 +89,8 @@ def run():
|
||||
os.environ[env_param] = env_str
|
||||
|
||||
|
||||
init_global()
|
||||
run()
|
||||
try:
|
||||
init_global()
|
||||
run()
|
||||
except Exception as error:
|
||||
print(f"run builtin code error: {error}\n")
|
||||
|
||||
Reference in New Issue
Block a user