修改删除日志逻辑

This commit is contained in:
whyour 2023-02-27 23:25:08 +08:00
parent 6c34045a48
commit c285026339
5 changed files with 57 additions and 4 deletions

View File

@ -152,6 +152,21 @@ export default (app: Router) => {
}
});
route.get(
'/detail',
async (req: Request, res: Response, next: NextFunction) => {
const logger: Logger = Container.get('logger');
try {
const cronService = Container.get(CronService);
const data = await cronService.find(req.query as any);
return res.send({ code: 200, data });
} catch (e) {
logger.error('🔥 error: %o', e);
return next(e);
}
},
);
route.post(
'/',
celebrate({

View File

@ -261,6 +261,15 @@ export default class CronService {
}
}
public async find(params: { log_path: string }): Promise<Crontab | null> {
try {
const result = await CrontabModel.findOne({ where: { ...params } });
return result;
} catch (error) {
throw error;
}
}
public async crontabs(params?: {
searchValue: string;
page: string;
@ -429,7 +438,7 @@ export default class CronService {
if (logFileExist) {
return getFileContentByName(`${absolutePath}`);
} else {
return '任务未运行或运行失败,请尝试手动运行';
return '任务未运行';
}
}

View File

@ -199,4 +199,27 @@ notify_api() {
fi
}
find_cron_api() {
local params=$1
local currentTimeStamp=$(date +%s)
local api=$(
curl -s --noproxy "*" "http://0.0.0.0:5600/open/crons/detail?$params&t=$currentTimeStamp" \
-H "Accept: application/json" \
-H "Authorization: Bearer $token" \
-H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36" \
-H "Content-Type: application/json;charset=UTF-8" \
-H "Origin: http://0.0.0.0:5700" \
-H "Referer: http://0.0.0.0:5700/crontab" \
-H "Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7" \
--compressed
)
data=$(echo "$api" | jq -r .data)
if [[ $data == 'null' ]]; then
echo -e ""
else
name=$(echo "$api" | jq -r .data.name)
echo -e "$name"
fi
}
get_token

View File

@ -6,7 +6,7 @@ dir_shell=$QL_DIR/shell
days=$1
## 删除运行js脚本的旧日志
## 删除运行脚本的旧日志
remove_js_log() {
local log_full_path_list=$(find $dir_log/ -name "*.log")
local diff_time
@ -18,7 +18,13 @@ remove_js_log() {
else
diff_time=$(($(date +%s) - $(date +%s -d "$log_date")))
fi
[[ $diff_time -gt $((${days} * 86400)) ]] && rm -vf $log
if [[ $diff_time -gt $((${days} * 86400)) ]]; then
local log_path=$(echo "$log" | sed "s,${dir_log},,g")
local result=$(find_cron_api "log_path=$log_path")
if [[ $result ]]; then
rm -vf $log
fi
fi
fi
done
}

View File

@ -54,7 +54,7 @@ const CronLogModal = ({
log &&
!logEnded(log) &&
!log.includes('重启面板') &&
!log.includes('任务未运行或运行失败,请尝试手动运行'),
!log.includes('任务未运行'),
);
setExecuting(hasNext);
autoScroll();