修复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

View File

@ -1,12 +1,13 @@
name: PublishDockerImage name: PublishDockerImage
on: on:
workflow_run: workflow_dispatch:
workflows: # workflow_run:
- BuildStatic # workflows:
branches: # - BuildStatic
- master # branches:
types: # - master
- completed # types:
# - completed
jobs: jobs:
build: build:

View File

@ -15,7 +15,7 @@ export default ({ app }: { app: Application }) => {
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true })); app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
app.use( app.use(
jwt({ secret: config.secret as string, algorithms: ['HS384'] }).unless({ jwt({ secret: config.secret as string, algorithms: ['HS384'] }).unless({
path: ['/api/login'], path: ['/api/login', '/api/crons/status'],
}), }),
); );
app.use((req, res, next) => { app.use((req, res, next) => {

View File

@ -37,8 +37,10 @@ RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
&& cp -f .env.example .env \ && cp -f .env.example .env \
&& chmod 777 ${QL_DIR}/shell/*.sh \ && chmod 777 ${QL_DIR}/shell/*.sh \
&& chmod 777 ${QL_DIR}/docker/*.sh \ && chmod 777 ${QL_DIR}/docker/*.sh \
&& npm install -g pm2 \
&& npm install -g pnpm \ && npm install -g pnpm \
&& pnpm install -g pm2 \
&& pnpm install -g ts-node \
&& pnpm i -g typescript \
&& rm -rf /root/.npm \ && rm -rf /root/.npm \
&& pnpm install --prod \ && pnpm install --prod \
&& rm -rf /root/.pnpm-store \ && rm -rf /root/.pnpm-store \

View File

@ -14,6 +14,8 @@ define_program() {
which_program="python3" which_program="python3"
elif [[ $p1 == *.sh ]]; then elif [[ $p1 == *.sh ]]; then
which_program="bash" which_program="bash"
elif [[ $p1 == *.ts ]]; then
which_program="ts-node"
else else
which_program="" which_program=""
fi fi
@ -91,11 +93,19 @@ run_normal() {
local begin_time=$(date '+%Y-%m-%d %H:%M:%S') local begin_time=$(date '+%Y-%m-%d %H:%M:%S')
echo -e "## 开始执行... $begin_time\n" | tee -a $log_path echo -e "## 开始执行... $begin_time\n" | tee -a $log_path
[[ $id ]] && update_cron "\"$id\"" "0" "$$" "$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 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" [[ $id ]] && update_cron "\"$id\"" "1" "" "$log_path"
local end_time=$(date '+%Y-%m-%d %H:%M:%S') local end_time=$(date '+%Y-%m-%d %H:%M:%S')
local diff_time=$(($(date +%s -d "$end_time") - $(date +%s -d "$begin_time"))) 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') local begin_time=$(date '+%Y-%m-%d %H:%M:%S')
echo -e "## 开始执行... $begin_time\n" | tee -a $log_path echo -e "## 开始执行... $begin_time\n" | tee -a $log_path
[[ $id ]] && update_cron "\"$id\"" "0" "$$" "$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 echo -e "\n各账号间已经在后台开始并发执行前台不输入日志日志直接写入文件中。\n" | tee -a $log_path
single_log_time=$(date "+%Y-%m-%d-%H-%M-%S.%N") 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 & timeout $command_timeout_time $which_program $p1 &>$single_log_path &
done 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" [[ $id ]] && update_cron "\"$id\"" "1" "" "$log_path"
local end_time=$(date '+%Y-%m-%d %H:%M:%S') local end_time=$(date '+%Y-%m-%d %H:%M:%S')
local diff_time=$(($(date +%s -d "$end_time") - $(date +%s -d "$begin_time"))) 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') local begin_time=$(date '+%Y-%m-%d %H:%M:%S')
echo -e "## 开始执行... $begin_time\n" | tee -a $log_path echo -e "## 开始执行... $begin_time\n" | tee -a $log_path
[[ $id ]] && update_cron "\"$id\"" "0" "$$" "$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 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" [[ $id ]] && update_cron "\"$id\"" "1" "" "$log_path"
local end_time=$(date '+%Y-%m-%d %H:%M:%S') local end_time=$(date '+%Y-%m-%d %H:%M:%S')
local diff_time=$(($(date +%s -d "$end_time") - $(date +%s -d "$begin_time"))) local diff_time=$(($(date +%s -d "$end_time") - $(date +%s -d "$begin_time")))

View File

@ -234,15 +234,9 @@ usage() {
## 更新qinglong ## 更新qinglong
update_qinglong() { update_qinglong() {
local no_restart="$1" patch_version
echo -e "--------------------------------------------------------------\n"
if [ -f /ql/db/cookie.db ]; then
echo -e "检测到旧的db文件拷贝为新db...\n"
mv /ql/db/cookie.db /ql/db/env.db
rm /ql/db/cookie.db
echo
fi
local no_restart="$1"
[ -f $dir_root/package.json ] && ql_depend_old=$(cat $dir_root/package.json) [ -f $dir_root/package.json ] && ql_depend_old=$(cat $dir_root/package.json)
reset_romote_url ${dir_root} "${github_proxy_url}https://github.com/whyour/qinglong.git" reset_romote_url ${dir_root} "${github_proxy_url}https://github.com/whyour/qinglong.git"
git_pull_scripts $dir_root git_pull_scripts $dir_root
@ -272,9 +266,8 @@ update_qinglong() {
fi fi
if [[ $exit_status -eq 0 ]]; then if [[ $exit_status -eq 0 ]]; then
echo -e "\n更新$ql_static_repo成功...\n" echo -e "\n更新$ql_static_repo成功...\n"
cd $ql_static_repo local static_version=$(cat /ql/src/version.ts | perl -pe "s|.*\'(.*)\';\.*|\1|" | head -1)
commit_id=$(git rev-parse --short HEAD) echo -e "\n当前版本 $static_version...\n"
echo -e "\n当前静态资源版本 $commit_id...\n"
cd $dir_root cd $dir_root
rm -rf $dir_root/build && rm -rf $dir_root/dist rm -rf $dir_root/build && rm -rf $dir_root/dist
cp -rf $ql_static_repo/* $dir_root cp -rf $ql_static_repo/* $dir_root
@ -290,6 +283,20 @@ update_qinglong() {
} }
patch_version() {
if [ -f /ql/db/cookie.db ]; then
echo -e "检测到旧的db文件拷贝为新db...\n"
mv /ql/db/cookie.db /ql/db/env.db
rm /ql/db/cookie.db
echo
fi
if ! type ts-node >/dev/null 2>&1; then
pnpm i -g ts-node
pnpm i -g typescript
fi
}
reload_pm2() { reload_pm2() {
pm2 l >/dev/null 2>&1 pm2 l >/dev/null 2>&1