提交 | 用户 | 时间
|
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.ApiAccessLogService; |
|
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 |
@Component |
|
17 |
@Slf4j |
|
18 |
public class AccessLogCleanJob { |
|
19 |
|
|
20 |
@Resource |
|
21 |
private ApiAccessLogService apiAccessLogService; |
|
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("accessLogCleanJob") |
|
34 |
@TenantIgnore |
|
35 |
public void execute() { |
|
36 |
Integer count = apiAccessLogService.cleanAccessLog(JOB_CLEAN_RETAIN_DAY, DELETE_LIMIT); |
|
37 |
log.info("[execute][定时执行清理访问日志数量 ({}) 个]", count); |
|
38 |
} |
|
39 |
|
|
40 |
} |