修复任务统计日志

This commit is contained in:
whyour 2026-06-07 15:15:12 +08:00
parent c14390cf41
commit ad92e0c2c0
2 changed files with 26 additions and 4 deletions

View File

@ -226,12 +226,22 @@ record_cron_stat() {
local elapsed="${3:-0}" local elapsed="${3:-0}"
[[ $ref_id ]] && [[ $ref_id -gt 0 ]] 2>/dev/null || return [[ $ref_id ]] && [[ $ref_id -gt 0 ]] 2>/dev/null || return
curl -s --noproxy "*" "http://localhost:${ql_port:-5700}/open/dashboard/record" \ local api=$(
curl -s --noproxy "*" "http://localhost:${ql_port:-5700}/open/dashboard/record" \
-X POST \ -X POST \
-H "Authorization: Bearer ${__ql_token__}" \ -H "Authorization: Bearer ${__ql_token__}" \
-H "Content-Type: application/json;charset=UTF-8" \ -H "Content-Type: application/json;charset=UTF-8" \
--data-raw "{\"ref_id\":$ref_id,\"code\":$exit_code,\"elapsed\":$elapsed}" \ --data-raw "{\"ref_id\":$ref_id,\"code\":$exit_code,\"elapsed\":$elapsed}" \
--compressed --compressed
)
code=$(echo "$api" | jq -r .code)
message=$(echo "$api" | jq -r .message)
if [[ $code != 200 ]]; then
if [[ ! $message ]]; then
message="$api"
fi
echo -e "${message}"
fi
} }
get_token get_token

View File

@ -98,11 +98,20 @@ enter_script_workdir() {
# 如果定时任务显式指定了工作目录,优先使用 # 如果定时任务显式指定了工作目录,优先使用
if [[ -n "${work_dir:=}" ]]; then if [[ -n "${work_dir:=}" ]]; then
local _target_dir
if [[ "${work_dir}" == /* ]]; then if [[ "${work_dir}" == /* ]]; then
cd "${work_dir}" _target_dir="${work_dir}"
else else
cd "${dir_scripts}/${work_dir}" _target_dir="${dir_scripts}/${work_dir}"
fi fi
if [[ ! -d "${_target_dir}" ]]; then
echo -e "错误:工作目录不存在 ${_target_dir}"
exit 1
fi
cd "${_target_dir}" || {
echo -e "错误:无法进入工作目录 ${_target_dir}"
exit 1
}
# 仍然处理 file_param 中的路径前缀,确保命令路径正确 # 仍然处理 file_param 中的路径前缀,确保命令路径正确
if [[ ${file_param} =~ "/" ]]; then if [[ ${file_param} =~ "/" ]]; then
local script_name="${file_param##*/}" local script_name="${file_param##*/}"
@ -116,7 +125,10 @@ enter_script_workdir() {
fi fi
# 自动检测:从 file_param 中提取脚本所在目录 # 自动检测:从 file_param 中提取脚本所在目录
cd $dir_scripts cd $dir_scripts || {
echo -e "错误:无法进入 scripts 目录 ${dir_scripts}"
exit 1
}
if [[ ${file_param} =~ "/" ]]; then if [[ ${file_param} =~ "/" ]]; then
local script_dir="${file_param%/*}" local script_dir="${file_param%/*}"
local script_name="${file_param##*/}" local script_name="${file_param##*/}"