feat: add more clear job
This commit is contained in:
parent
63de6d7aa5
commit
b6bca6c250
@ -21,6 +21,8 @@ export function initCronjob() {
|
||||
await Promise.all([
|
||||
statDailyUsage().catch(logger.error),
|
||||
clearMonitorDataDaily().catch(logger.error),
|
||||
clearMonitorEventDaily().catch(logger.error),
|
||||
clearAuditLogDaily().catch(logger.error),
|
||||
dailyHTTPCertCheckNotify().catch(logger.error),
|
||||
]);
|
||||
|
||||
@ -169,6 +171,60 @@ async function clearMonitorDataDaily() {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear over 2 week data
|
||||
*/
|
||||
async function clearMonitorEventDaily() {
|
||||
if (env.disableAutoClear) {
|
||||
return;
|
||||
}
|
||||
|
||||
const date = dayjs().subtract(2, 'weeks').toDate();
|
||||
logger.info(
|
||||
'[clearMonitorEventDaily] Start clear monitor data before:',
|
||||
date.toISOString()
|
||||
);
|
||||
const res = await prisma.monitorEvent.deleteMany({
|
||||
where: {
|
||||
createdAt: {
|
||||
lte: date,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
logger.info(
|
||||
'[clearMonitorEventDaily] Clear monitor completed, delete record:',
|
||||
res.count
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear over 4 week data
|
||||
*/
|
||||
async function clearAuditLogDaily() {
|
||||
if (env.disableAutoClear) {
|
||||
return;
|
||||
}
|
||||
|
||||
const date = dayjs().subtract(4, 'weeks').toDate();
|
||||
logger.info(
|
||||
'[clearAuditLogDaily] Start clear log data before:',
|
||||
date.toISOString()
|
||||
);
|
||||
const res = await prisma.workspaceAuditLog.deleteMany({
|
||||
where: {
|
||||
createdAt: {
|
||||
lte: date,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
logger.info(
|
||||
'[clearAuditLogDaily] Clear log completed, delete record:',
|
||||
res.count
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Https notify
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user