修复定时删除日志设置,主持设置大于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 { exec } from 'child_process';
import { import {
ToadScheduler, ToadScheduler,
SimpleIntervalJob, LongIntervalJob,
Task, AsyncTask,
SimpleIntervalSchedule, SimpleIntervalSchedule,
} from 'toad-scheduler'; } from 'toad-scheduler';
@ -87,43 +87,51 @@ export default class ScheduleService {
name, name,
command, command,
); );
const task = new Task(name, async () => { const task = new AsyncTask(
try { name,
exec( async () => {
command, return new Promise(async (resolve, reject) => {
{ maxBuffer: this.maxBuffer }, try {
async (error, stdout, stderr) => { exec(
if (error) { command,
await this.logger.info( { maxBuffer: this.maxBuffer },
'执行任务%s失败时间%s, 错误信息:%j', async (error, stdout, stderr) => {
command, if (error) {
new Date().toLocaleString(), await this.logger.info(
error, '执行任务%s失败时间%s, 错误信息:%j',
); command,
} new Date().toLocaleString(),
error,
);
}
if (stderr) { if (stderr) {
await this.logger.info( await this.logger.info(
'执行任务%s失败时间%s, 错误信息:%j', '执行任务%s失败时间%s, 错误信息:%j',
command, command,
new Date().toLocaleString(), new Date().toLocaleString(),
stderr, stderr,
); );
} }
}, resolve();
); },
} catch (error) { );
await this.logger.info( } catch (error) {
reject(error);
}
});
},
(err) => {
this.logger.info(
'执行任务%s失败时间%s, 错误信息:%j', '执行任务%s失败时间%s, 错误信息:%j',
command, command,
new Date().toLocaleString(), new Date().toLocaleString(),
error, err,
); );
} finally { },
} );
});
const job = new SimpleIntervalJob({ ...schedule }, task, _id); const job = new LongIntervalJob({ ...schedule }, task, _id);
this.intervalSchedule.addIntervalJob(job); this.intervalSchedule.addIntervalJob(job);
} }

View File

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