mirror of
https://github.com/whyour/qinglong.git
synced 2026-07-01 04:40:38 +08:00
增加任务统计
This commit is contained in:
@@ -220,4 +220,18 @@ update_auth_config() {
|
||||
fi
|
||||
}
|
||||
|
||||
record_cron_stat() {
|
||||
local ref_id="$1"
|
||||
local exit_code="${2:-0}"
|
||||
local elapsed="${3:-0}"
|
||||
[[ $ref_id ]] && [[ $ref_id -gt 0 ]] 2>/dev/null || return
|
||||
|
||||
curl -s --noproxy "*" "http://0.0.0.0:${ql_port:-5700}/open/dashboard/record" \
|
||||
-X POST \
|
||||
-H "Authorization: Bearer ${__ql_token__}" \
|
||||
-H "Content-Type: application/json;charset=UTF-8" \
|
||||
--data-raw "{\"ref_id\":$ref_id,\"code\":$exit_code,\"elapsed\":$elapsed}" \
|
||||
--compressed
|
||||
}
|
||||
|
||||
get_token
|
||||
|
||||
+2
-1
@@ -294,6 +294,7 @@ fi
|
||||
set_u_on="false"
|
||||
check_nounset
|
||||
main "${task_shell_params[@]}"
|
||||
_task_exit_code=$?
|
||||
if [[ "$set_u_on" == 'true' ]]; then
|
||||
set -u
|
||||
fi
|
||||
@@ -305,4 +306,4 @@ if [[ $isJsOrPythonFile == 'true' ]]; then
|
||||
fi
|
||||
run_task_after "${task_shell_params[@]}"
|
||||
clear_env
|
||||
handle_task_end "${task_shell_params[@]}"
|
||||
handle_task_end "${task_shell_params[@]}" "$_task_exit_code"
|
||||
|
||||
+12
-5
@@ -388,18 +388,25 @@ 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="(手动停止)"
|
||||
|
||||
local exit_code="${@: -1}"
|
||||
[[ "$diff_time" == 0 ]] && diff_time=1
|
||||
|
||||
if [[ $ID ]]; then
|
||||
local error=$(update_cron "\"$ID\"" "1" "$$" "$log_path" "$begin_timestamp" "$diff_time")
|
||||
if [[ $error ]]; then
|
||||
error_message=", 任务状态更新失败(${error})"
|
||||
error_message=", 状态更新失败(${error})"
|
||||
fi
|
||||
fi
|
||||
echo -e "\n## 执行结束$suffix... $end_time 耗时 $diff_time 秒${error_message:=} "
|
||||
|
||||
record_cron_stat "$ID" "${exit_code:-0}" "$diff_time"
|
||||
|
||||
if [[ "${MANUAL:=}" == "true" ]]; then
|
||||
echo -e "\n## 已停止 ⏹... $end_time 耗时 $diff_time 秒${error_message:=} "
|
||||
elif [[ $exit_code -eq 0 ]]; then
|
||||
echo -e "\n## 完成 ✅... $end_time 耗时 $diff_time 秒${error_message:=} "
|
||||
else
|
||||
echo -e "\n## 失败 ❌ (退出码 ${exit_code})... $end_time 耗时 $diff_time 秒${error_message:=} "
|
||||
fi
|
||||
}
|
||||
|
||||
init_env
|
||||
|
||||
Reference in New Issue
Block a user