修复日志删除逻辑

This commit is contained in:
whyour 2023-03-10 14:21:52 +08:00
parent b2167ae5e4
commit 7b2956eb0a
2 changed files with 9 additions and 5 deletions

View File

@ -18,7 +18,7 @@ import { TASK_PREFIX, QL_PREFIX } from '../config/const';
@Service()
export default class CronService {
constructor(@Inject('logger') private logger: winston.Logger) {}
constructor(@Inject('logger') private logger: winston.Logger) { }
private isSixCron(cron: Crontab) {
const { schedule } = cron;
@ -264,9 +264,9 @@ export default class CronService {
}
}
public async find(params: { log_path: string }): Promise<Crontab | null> {
public async find({ log_path }: { log_path: string }): Promise<Crontab | null> {
try {
const result = await CrontabModel.findOne({ where: { ...params } });
const result = await CrontabModel.findOne({ where: { log_path } });
return result;
} catch (error) {
throw error;

View File

@ -19,10 +19,14 @@ remove_js_log() {
diff_time=$(($(date +%s) - $(date +%s -d "$log_date")))
fi
if [[ $diff_time -gt $((${days} * 86400)) ]]; then
local log_path=$(echo "$log" | sed "s,${dir_log},,g")
local log_path=$(echo "$log" | sed "s,${dir_log}/,,g")
local result=$(find_cron_api "log_path=$log_path")
if [[ $result ]]; then
echo -e "查询文件 $log_path"
if [[ -z $result ]]; then
echo -e "删除中~"
rm -vf $log
else
echo -e "正在被 $result 使用,跳过~"
fi
fi
fi