houzhongyi
2024-07-11 e7c1260db32209a078a962aaa0ad5492c35774fb
提交 | 用户 | 时间
e7c126 1 package com.iailab.module.infra.job.logger;
H 2
3 import com.iailab.framework.tenant.core.aop.TenantIgnore;
4 import com.iailab.module.infra.service.logger.ApiErrorLogService;
5 import com.xxl.job.core.handler.annotation.XxlJob;
6 import lombok.extern.slf4j.Slf4j;
7 import org.springframework.stereotype.Component;
8
9 import javax.annotation.Resource;
10
11 /**
12  * 物理删除 N 天前的错误日志的 Job
13  *
14  * @author j-sentinel
15  */
16 @Slf4j
17 @Component
18 public class ErrorLogCleanJob {
19
20     @Resource
21     private ApiErrorLogService apiErrorLogService;
22
23     /**
24      * 清理超过(14)天的日志
25      */
26     private static final Integer JOB_CLEAN_RETAIN_DAY = 14;
27
28     /**
29      * 每次删除间隔的条数,如果值太高可能会造成数据库的压力过大
30      */
31     private static final Integer DELETE_LIMIT = 100;
32
33     @XxlJob("errorLogCleanJob")
34     @TenantIgnore
35     public void execute() {
36         Integer count = apiErrorLogService.cleanErrorLog(JOB_CLEAN_RETAIN_DAY,DELETE_LIMIT);
37         log.info("[execute][定时执行清理错误日志数量 ({}) 个]", count);
38     }
39
40 }