From 43d6ac207160335b60cafd299d3c4343086d7606 Mon Sep 17 00:00:00 2001 From: whyour Date: Tue, 31 Dec 2024 00:17:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=89=8B=E5=8A=A8=E5=81=9C?= =?UTF-8?q?=E6=AD=A2=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shell/preload/sitecustomize.js | 8 +++++++- shell/preload/sitecustomize.py | 10 +++++++++- shell/share.sh | 4 +++- shell/task.sh | 2 +- src/utils/const.ts | 2 ++ 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/shell/preload/sitecustomize.js b/shell/preload/sitecustomize.js index 6dfc7095..5a4cdfbf 100644 --- a/shell/preload/sitecustomize.js +++ b/shell/preload/sitecustomize.js @@ -56,7 +56,9 @@ function run() { for (const key in newEnvObject) { process.env[key] = newEnvObject[key]; } - console.log(output); + if (output) { + console.log(output); + } if (task_before) { console.log('执行前置命令结束\n'); } @@ -89,6 +91,10 @@ try { return; } + process.on('SIGTERM', (code) => { + process.exit(15); + }); + run(); const { sendNotify } = require('./notify.js'); diff --git a/shell/preload/sitecustomize.py b/shell/preload/sitecustomize.py index 50d0e8f7..b3b5ad96 100644 --- a/shell/preload/sitecustomize.py +++ b/shell/preload/sitecustomize.py @@ -5,6 +5,7 @@ import json import builtins import sys import env +import signal def try_parse_int(value): @@ -63,7 +64,8 @@ def run(): for key, value in env_json.items(): os.environ[key] = value - print(output) + if len(output) > 0: + print(output) if task_before: print("执行前置命令结束") @@ -95,7 +97,13 @@ def run(): os.environ[env_param] = env_str +def handle_sigterm(signum, frame): + sys.exit(15) + + try: + signal.signal(signal.SIGTERM, handle_sigterm) + run() from notify import send diff --git a/shell/share.sh b/shell/share.sh index 9fb63984..93994f20 100755 --- a/shell/share.sh +++ b/shell/share.sh @@ -467,10 +467,12 @@ handle_task_end() { local end_time=$(format_time "$time_format" "$etime") local end_timestamp=$(format_timestamp "$time_format" "$etime") local diff_time=$(($end_timestamp - $begin_timestamp)) + local suffix="" + [[ "$MANUAL" == "true" ]] && suffix="(手动停止)" [[ "$diff_time" == 0 ]] && diff_time=1 - echo -e "\n## 执行结束... $end_time 耗时 $diff_time 秒     " + echo -e "\n## 执行结束$suffix... $end_time 耗时 $diff_time 秒     " [[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time" } diff --git a/shell/task.sh b/shell/task.sh index bf0348d2..a51eeaef 100755 --- a/shell/task.sh +++ b/shell/task.sh @@ -6,7 +6,7 @@ dir_shell=$QL_DIR/shell trap "single_hanle" 2 3 20 15 14 19 1 single_hanle() { - eval handle_task_end "$@" "$cmd" + eval MANUAL=true handle_task_end "$@" "$cmd" exit 1 } diff --git a/src/utils/const.ts b/src/utils/const.ts index dd45e08d..92297f44 100644 --- a/src/utils/const.ts +++ b/src/utils/const.ts @@ -6,4 +6,6 @@ export const LANG_MAP = { '.mjs': 'javascript', '.sh': 'shell', '.ts': 'typescript', + '.ini': 'ini', + '.json': 'json' };