修复task_before出错任务中断

This commit is contained in:
hanhh
2021-07-12 23:18:17 +08:00
parent dd424237e2
commit cad1d86caf
5 changed files with 62 additions and 26 deletions
+32 -6
View File
@@ -14,6 +14,8 @@ define_program() {
which_program="python3"
elif [[ $p1 == *.sh ]]; then
which_program="bash"
elif [[ $p1 == *.ts ]]; then
which_program="ts-node"
else
which_program=""
fi
@@ -91,11 +93,19 @@ run_normal() {
local begin_time=$(date '+%Y-%m-%d %H:%M:%S')
echo -e "## 开始执行... $begin_time\n" | tee -a $log_path
[[ $id ]] && update_cron "\"$id\"" "0" "$$" "$log_path"
. $file_task_before
if [[ $(. $file_task_before) ]]; then
. $file_task_before
else
echo -e "## task_before执行失败,自行检查\n" | tee -a $log_path
fi
timeout $command_timeout_time $which_program $p1 2>&1 | tee -a $log_path
. $file_task_after
if [[ $(. $file_task_after) ]]; then
. $file_task_after
else
echo -e "## task_after执行失败,自行检查\n" | tee -a $log_path
fi
[[ $id ]] && update_cron "\"$id\"" "1" "" "$log_path"
local end_time=$(date '+%Y-%m-%d %H:%M:%S')
local diff_time=$(($(date +%s -d "$end_time") - $(date +%s -d "$begin_time")))
@@ -125,7 +135,11 @@ run_concurrent() {
local begin_time=$(date '+%Y-%m-%d %H:%M:%S')
echo -e "## 开始执行... $begin_time\n" | tee -a $log_path
[[ $id ]] && update_cron "\"$id\"" "0" "$$" "$log_path"
. $file_task_before
if [[ $(. $file_task_before) ]]; then
. $file_task_before
else
echo -e "## task_before执行失败,自行检查\n" | tee -a $log_path
fi
echo -e "\n各账号间已经在后台开始并发执行,前台不输入日志,日志直接写入文件中。\n" | tee -a $log_path
single_log_time=$(date "+%Y-%m-%d-%H-%M-%S.%N")
@@ -135,7 +149,11 @@ run_concurrent() {
timeout $command_timeout_time $which_program $p1 &>$single_log_path &
done
. $file_task_after
if [[ $(. $file_task_after) ]]; then
. $file_task_after
else
echo -e "## task_after执行失败,自行检查\n" | tee -a $log_path
fi
[[ $id ]] && update_cron "\"$id\"" "1" "" "$log_path"
local end_time=$(date '+%Y-%m-%d %H:%M:%S')
local diff_time=$(($(date +%s -d "$end_time") - $(date +%s -d "$begin_time")))
@@ -154,11 +172,19 @@ run_else() {
local begin_time=$(date '+%Y-%m-%d %H:%M:%S')
echo -e "## 开始执行... $begin_time\n" | tee -a $log_path
[[ $id ]] && update_cron "\"$id\"" "0" "$$" "$log_path"
. $file_task_before
if [[ $(. $file_task_before) ]]; then
. $file_task_before
else
echo -e "## task_before执行失败,自行检查\n" | tee -a $log_path
fi
timeout $command_timeout_time "$@" 2>&1 | tee -a $log_path
. $file_task_after
if [[ $(. $file_task_after) ]]; then
. $file_task_after
else
echo -e "## task_after执行失败,自行检查\n" | tee -a $log_path
fi
[[ $id ]] && update_cron "\"$id\"" "1" "" "$log_path"
local end_time=$(date '+%Y-%m-%d %H:%M:%S')
local diff_time=$(($(date +%s -d "$end_time") - $(date +%s -d "$begin_time")))