mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-22 22:36:06 +08:00
修改 task 命令生成日志逻辑和关联任务查询
This commit is contained in:
parent
d6cfb18f06
commit
6e5d89c197
|
@ -49,7 +49,7 @@ export default class EnvService {
|
|||
}
|
||||
|
||||
public async update(payload: Env): Promise<Env> {
|
||||
const doc = await this.getDb({ id: payload.id })
|
||||
const doc = await this.getDb({ id: payload.id });
|
||||
const tab = new Env({ ...doc, ...payload });
|
||||
const newDoc = await this.updateDb(tab);
|
||||
await this.set_envs();
|
||||
|
@ -146,7 +146,6 @@ export default class EnvService {
|
|||
}
|
||||
try {
|
||||
const result = await this.find(condition, [
|
||||
['status', 'ASC'],
|
||||
['position', 'DESC'],
|
||||
['createdAt', 'ASC'],
|
||||
]);
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
trap "single_hanle" 2 20 15 14
|
||||
single_hanle() {
|
||||
handle_task_after "$@"
|
||||
exit 1
|
||||
}
|
||||
|
||||
random_delay() {
|
||||
local random_delay_max=$RandomDelay
|
||||
if [[ $random_delay_max ]] && [[ $random_delay_max -gt 0 ]]; then
|
||||
|
@ -92,40 +86,6 @@ check_server() {
|
|||
fi
|
||||
}
|
||||
|
||||
handle_task_before() {
|
||||
begin_time=$(format_time "$time_format" "$time")
|
||||
begin_timestamp=$(format_timestamp "$time_format" "$time")
|
||||
|
||||
[[ $ID ]] && update_cron "\"$ID\"" "0" "$$" "$log_path" "$begin_timestamp"
|
||||
|
||||
echo -e "## 开始执行... $begin_time\n"
|
||||
|
||||
[[ $is_macos -eq 0 ]] && check_server
|
||||
|
||||
if [[ -s $task_error_log_path ]]; then
|
||||
eval cat $task_error_log_path $cmd
|
||||
eval echo -e "加载 config.sh 出错,请手动检查" $cmd
|
||||
eval echo $cmd
|
||||
fi
|
||||
|
||||
. $file_task_before "$@"
|
||||
}
|
||||
|
||||
handle_task_after() {
|
||||
. $file_task_after "$@"
|
||||
|
||||
local etime=$(date "+$time_format")
|
||||
local end_time=$(format_time "$time_format" "$etime")
|
||||
local end_timestamp=$(format_timestamp "$time_format" "$etime")
|
||||
local diff_time=$(($end_timestamp - $begin_timestamp))
|
||||
|
||||
[[ "$diff_time" == 0 ]] && diff_time=1
|
||||
|
||||
echo -e "\n\n## 执行结束... $end_time 耗时 $diff_time 秒 "
|
||||
|
||||
[[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time"
|
||||
}
|
||||
|
||||
## 正常运行单个脚本,$1:传入参数
|
||||
run_normal() {
|
||||
local file_param=$1
|
||||
|
|
|
@ -500,6 +500,36 @@ init_nginx() {
|
|||
sed -i "s,IPV6_CONFIG,${ipv6Str},g" /etc/nginx/conf.d/front.conf
|
||||
}
|
||||
|
||||
handle_task_before() {
|
||||
[[ $ID ]] && update_cron "\"$ID\"" "0" "$$" "$log_path" "$begin_timestamp"
|
||||
|
||||
echo -e "## 开始执行... $begin_time\n"
|
||||
|
||||
[[ $is_macos -eq 0 ]] && check_server
|
||||
|
||||
if [[ -s $task_error_log_path ]]; then
|
||||
cat $task_error_log_path
|
||||
echo -e "加载 config.sh 出错,请手动检查"
|
||||
fi
|
||||
|
||||
. $file_task_before "$@"
|
||||
}
|
||||
|
||||
handle_task_after() {
|
||||
. $file_task_after "$@"
|
||||
|
||||
local etime=$(date "+$time_format")
|
||||
local end_time=$(format_time "$time_format" "$etime")
|
||||
local end_timestamp=$(format_timestamp "$time_format" "$etime")
|
||||
local diff_time=$(($end_timestamp - $begin_timestamp))
|
||||
|
||||
[[ "$diff_time" == 0 ]] && diff_time=1
|
||||
|
||||
echo -e "\n\n## 执行结束... $end_time 耗时 $diff_time 秒 "
|
||||
|
||||
[[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time"
|
||||
}
|
||||
|
||||
init_env
|
||||
detect_termux
|
||||
detect_macos
|
||||
|
|
|
@ -5,6 +5,12 @@ dir_shell=$QL_DIR/shell
|
|||
. $dir_shell/share.sh
|
||||
. $dir_shell/api.sh
|
||||
|
||||
trap "single_hanle" 2 3 20 15 14
|
||||
single_hanle() {
|
||||
eval handle_task_after "$@" "$cmd"
|
||||
exit 1
|
||||
}
|
||||
|
||||
## 选择python3还是node
|
||||
define_program() {
|
||||
local file_param=$1
|
||||
|
@ -32,10 +38,11 @@ handle_log_path() {
|
|||
file_param="task"
|
||||
fi
|
||||
|
||||
local suffix=""
|
||||
if [[ ! -z $ID ]]; then
|
||||
suffix="_${ID}"
|
||||
if [[ -z $ID ]]; then
|
||||
ID=$(cat $list_crontab_user | grep -E "$cmd_task $file_param" | perl -pe "s|.*ID=(.*) $cmd_task $file_param\.*|\1|" | head -1 | awk -F " " '{print $1}')
|
||||
fi
|
||||
local suffix="_${ID}"
|
||||
|
||||
time=$(date "+$mtime_format")
|
||||
log_time=$(format_log_time "$mtime_format" "$time")
|
||||
log_dir_tmp="${file_param##*/}"
|
||||
|
@ -52,10 +59,9 @@ handle_log_path() {
|
|||
log_dir="${log_dir_tmp%.*}${suffix}"
|
||||
log_path="$log_dir/$log_time.log"
|
||||
cmd=">> $dir_log/$log_path 2>&1"
|
||||
make_dir "$dir_log/$log_dir"
|
||||
if [[ "$show_log" == "true" ]]; then
|
||||
cmd=""
|
||||
else
|
||||
make_dir "$dir_log/$log_dir"
|
||||
cmd="2>&1 | tee -a $dir_log/$log_path"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -73,6 +79,11 @@ format_params() {
|
|||
# params=$(echo "$@" | sed -E 's/([^ ])&([^ ])/\1\\\&\2/g')
|
||||
}
|
||||
|
||||
init_begin_time() {
|
||||
begin_time=$(format_time "$time_format" "$time")
|
||||
begin_timestamp=$(format_timestamp "$time_format" "$time")
|
||||
}
|
||||
|
||||
while getopts ":lm:" opt; do
|
||||
case $opt in
|
||||
l)
|
||||
|
@ -92,8 +103,9 @@ fi
|
|||
format_params "$@"
|
||||
define_program "$@"
|
||||
handle_log_path "$@"
|
||||
init_begin_time
|
||||
|
||||
eval . $dir_shell/otask.sh "$cmd"
|
||||
[[ -f "$dir_log/$log_path" ]] && cat "$dir_log/$log_path"
|
||||
[[ -f "$dir_log/$log_path" ]] && [[ ! $show_log ]] && cat "$dir_log/$log_path"
|
||||
|
||||
exit 0
|
||||
|
|
Loading…
Reference in New Issue
Block a user