From 23fd595582b8e413abfa5302f2a4e356921f1447 Mon Sep 17 00:00:00 2001 From: whyour Date: Mon, 5 Dec 2022 13:18:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20timeout=20=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E9=BB=98=E8=AE=A4=E4=BF=A1=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shell/otask.sh | 12 +++++++++--- shell/task.sh | 2 +- shell/update.sh | 12 ++++++------ 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/shell/otask.sh b/shell/otask.sh index 8c9851e2..93512936 100644 --- a/shell/otask.sh +++ b/shell/otask.sh @@ -5,6 +5,12 @@ dir_shell=$QL_DIR/shell . $dir_shell/share.sh . $dir_shell/api.sh +trap "single_hanle" 2 20 15 +single_hanle() { + handle_task_after "$@" + exit 1 +} + random_delay() { local random_delay_max=$RandomDelay if [[ $random_delay_max ]] && [[ $random_delay_max -gt 0 ]]; then @@ -115,7 +121,7 @@ handle_task_after() { local end_time=$(format_time "$time_format" "$etime") local end_timestamp=$(format_timestamp "$time_format" "$etime") local diff_time=$(($end_timestamp - $begin_timestamp)) - + [[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time" echo -e "\n\n## 执行结束... $end_time 耗时 $diff_time 秒" echo -e "\n     " @@ -150,7 +156,7 @@ run_concurrent() { local envs=$(eval echo "\$${env_param}") local array=($(echo $envs | sed 's/&/ /g')) - local tempArr=$(echo $num_param | sed "s/-max/-${#array[@]}/g" | sed "s/max-/${#array[@]}-/g" | perl -pe "s|(\d+)(-\|~\|_)(\d+)|{\1..\3}|g") + local tempArr=$(echo $num_param | sed "s/-max/-${#array[@]}/g" | sed "s/max-/${#array[@]}-/g" | perl -pe "s|(\d+)(-\|~\|_)(\d+)|{\1..\3}|g") local runArr=($(eval echo $tempArr)) runArr=($(awk -v RS=' ' '!a[$1]++' <<<${runArr[@]})) @@ -198,7 +204,7 @@ run_designated() { local envs=$(eval echo "\$${env_param}") local array=($(echo $envs | sed 's/&/ /g')) - local tempArr=$(echo $num_param | sed "s/-max/-${#array[@]}/g" | sed "s/max-/${#array[@]}-/g" | perl -pe "s|(\d+)(-\|~\|_)(\d+)|{\1..\3}|g") + local tempArr=$(echo $num_param | sed "s/-max/-${#array[@]}/g" | sed "s/max-/${#array[@]}-/g" | perl -pe "s|(\d+)(-\|~\|_)(\d+)|{\1..\3}|g") local runArr=($(eval echo $tempArr)) runArr=($(awk -v RS=' ' '!a[$1]++' <<<${runArr[@]})) diff --git a/shell/task.sh b/shell/task.sh index 8f9864b4..1051416c 100755 --- a/shell/task.sh +++ b/shell/task.sh @@ -56,7 +56,7 @@ format_params() { time_format="%Y-%m-%d %H:%M:%S" timeoutCmd="" if type timeout &>/dev/null; then - timeoutCmd="timeout -k 10s $command_timeout_time " + timeoutCmd="timeout --foreground -s 2 -k 10s $command_timeout_time " fi params=$(echo "$@" | sed -E 's/([^ ])&([^ ])/\1\\\&\2/g') } diff --git a/shell/update.sh b/shell/update.sh index 0d54a78b..f2b7b346 100755 --- a/shell/update.sh +++ b/shell/update.sh @@ -188,7 +188,7 @@ update_raw() { echo -e "下载 ${raw_file_name} 成功...\n" cd $dir_raw local filename="raw_${raw_file_name}" - local cron_id=$(cat $list_crontab_user | grep -E "$cmd_task $filename" | perl -pe "s|.*ID=(.*) $cmd_task $filename\.*|\1|" | head -1 | head -1 | awk -F " " '{print $1}') + local cron_id=$(cat $list_crontab_user | grep -E "$cmd_task.* $filename" | perl -pe "s|.*ID=(.*) $cmd_task.* $filename\.*|\1|" | head -1 | head -1 | awk -F " " '{print $1}') cp -f $raw_file_name $dir_scripts/${filename} cron_line=$( perl -ne "{ @@ -396,12 +396,12 @@ gen_list_repo() { filename=$(basename $file) cp -f $file "$dir_scripts/${uniq_path}/${filename}" echo "${uniq_path}/${filename}" >>"$dir_list_tmp/${uniq_path}_scripts.list" - cron_id=$(cat $list_crontab_user | grep -E "$cmd_task ${uniq_path}_${filename}" | perl -pe "s|.*ID=(.*) $cmd_task ${uniq_path}_${filename}\.*|\1|" | head -1 | awk -F " " '{print $1}') - if [[ $cron_id ]]; then - result=$(update_cron_command_api "$cmd_task ${uniq_path}/${filename}:$cron_id") - fi + # cron_id=$(cat $list_crontab_user | grep -E "$cmd_task.* ${uniq_path}_${filename}" | perl -pe "s|.*ID=(.*) $cmd_task.* ${uniq_path}_${filename}\.*|\1|" | head -1 | awk -F " " '{print $1}') + # if [[ $cron_id ]]; then + # result=$(update_cron_command_api "$cmd_task ${uniq_path}/${filename}:$cron_id") + # fi done - grep -E "${cmd_task} ${uniq_path}" ${list_crontab_user} | perl -pe "s|.*ID=(.*) ${cmd_task} (${uniq_path}.*)\.*|\2|" | awk -F " " '{print $1}' | sort -u >"$dir_list_tmp/${uniq_path}_user.list" + grep -E "${cmd_task}.* ${uniq_path}" ${list_crontab_user} | perl -pe "s|.*ID=(.*) ${cmd_task}.* (${uniq_path}.*)\.*|\2|" | awk -F " " '{print $1}' | sort -u >"$dir_list_tmp/${uniq_path}_user.list" cd $dir_current }