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