修复定时删除日志设置,主持设置大于24天

This commit is contained in:
whyour 2022-04-18 22:29:14 +08:00
parent 54e58c1e08
commit 8ad325686d
2 changed files with 43 additions and 33 deletions

View File

@ -5,8 +5,8 @@ import { Crontab } from '../data/cron';
import { exec } from 'child_process';
import {
ToadScheduler,
SimpleIntervalJob,
Task,
LongIntervalJob,
AsyncTask,
SimpleIntervalSchedule,
} from 'toad-scheduler';
@ -87,43 +87,51 @@ export default class ScheduleService {
name,
command,
);
const task = new Task(name, async () => {
try {
exec(
command,
{ maxBuffer: this.maxBuffer },
async (error, stdout, stderr) => {
if (error) {
await this.logger.info(
'执行任务%s失败时间%s, 错误信息:%j',
command,
new Date().toLocaleString(),
error,
);
}
const task = new AsyncTask(
name,
async () => {
return new Promise(async (resolve, reject) => {
try {
exec(
command,
{ maxBuffer: this.maxBuffer },
async (error, stdout, stderr) => {
if (error) {
await this.logger.info(
'执行任务%s失败时间%s, 错误信息:%j',
command,
new Date().toLocaleString(),
error,
);
}
if (stderr) {
await this.logger.info(
'执行任务%s失败时间%s, 错误信息:%j',
command,
new Date().toLocaleString(),
stderr,
);
}
},
);
} catch (error) {
await this.logger.info(
if (stderr) {
await this.logger.info(
'执行任务%s失败时间%s, 错误信息:%j',
command,
new Date().toLocaleString(),
stderr,
);
}
resolve();
},
);
} catch (error) {
reject(error);
}
});
},
(err) => {
this.logger.info(
'执行任务%s失败时间%s, 错误信息:%j',
command,
new Date().toLocaleString(),
error,
err,
);
} finally {
}
});
},
);
const job = new SimpleIntervalJob({ ...schedule }, task, _id);
const job = new LongIntervalJob({ ...schedule }, task, _id);
this.intervalSchedule.addIntervalJob(job);
}

View File

@ -57,7 +57,9 @@ export default class SystemService {
}
public async updateLogRemoveFrequency(frequency: number) {
const oDoc = await this.getLogRemoveFrequency();
const result = await this.updateAuthDb({
...oDoc,
type: AuthDataType.removeLogFrequency,
info: { frequency },
});