修复定时删除日志设置,主持设置大于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,7 +87,10 @@ export default class ScheduleService {
name, name,
command, command,
); );
const task = new Task(name, async () => { const task = new AsyncTask(
name,
async () => {
return new Promise(async (resolve, reject) => {
try { try {
exec( exec(
command, command,
@ -110,20 +113,25 @@ export default class ScheduleService {
stderr, stderr,
); );
} }
resolve();
}, },
); );
} catch (error) { } catch (error) {
await this.logger.info( 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 },
}); });