mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-25 00:15:06 +08:00
code review:访问日志、错误日志的清理 Job 实现
This commit is contained in:
@ -18,10 +18,12 @@ public interface ApiAccessLogApi {
|
||||
*/
|
||||
void createApiAccessLog(@Valid ApiAccessLogCreateReqDTO createDTO);
|
||||
|
||||
// TODO @j-sentinel:这个我们先提供接口在 API,而是 infra 模块自己清理先哈;
|
||||
/**
|
||||
* 清理 @param accessLogJobDay 天的访问日志
|
||||
*
|
||||
* @param accessLogJobDay 超过多少天就进行清理
|
||||
*/
|
||||
void jobCleanAccessLog(Integer accessLogJobDay);
|
||||
|
||||
}
|
||||
|
@ -18,10 +18,12 @@ public interface ApiErrorLogApi {
|
||||
*/
|
||||
void createApiErrorLog(@Valid ApiErrorLogCreateReqDTO createDTO);
|
||||
|
||||
// TODO @j-sentinel:这个我们先提供接口在 API,而是 infra 模块自己清理先哈;
|
||||
/**
|
||||
* 清理 @param errorLogJobDay 天的访问日志
|
||||
*
|
||||
* @param errorLogJobDay 超过多少天就进行清理
|
||||
*/
|
||||
void jobCleanErrorLog(Integer errorLogJobDay);
|
||||
|
||||
}
|
||||
|
@ -41,7 +41,12 @@ public interface JobLogMapper extends BaseMapperX<JobLogDO> {
|
||||
);
|
||||
}
|
||||
|
||||
// TODO @j-sentinel:一般来说,我们 mapper 只提供 crud 的操作,所以这个方法的命名,建议是 deleteByCreateTimeLt;
|
||||
// 然后,参数是 (crateTime, count),由 service 传入
|
||||
// 这里为什么有 lt 呢,这个其实是延续 spring data 的 method 描述的命名习惯,lt 表示小于;
|
||||
// 另外,timingJobCleanLog 的具体 sql 这么写,性能是比较差的;可以直接 delete * from job_log where create_time < xxx order by id limit 100;
|
||||
Integer timingJobCleanLog(@Param("jobCleanRetainDay") Integer jobCleanRetainDay);
|
||||
|
||||
// TODO @j-serntinel:optimize table infra_job_log 就可以啦?
|
||||
void optimizeTable();
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ public interface ApiAccessLogMapper extends BaseMapperX<ApiAccessLogDO> {
|
||||
);
|
||||
}
|
||||
|
||||
// TODO @j-sentinel:同 JobLogMapper 的一些优化点
|
||||
Integer jobCleanAccessLog(@Param("accessLogJobDay") Integer accessLogJobDay);
|
||||
|
||||
void optimizeTable();
|
||||
|
@ -43,6 +43,7 @@ public interface ApiErrorLogMapper extends BaseMapperX<ApiErrorLogDO> {
|
||||
);
|
||||
}
|
||||
|
||||
// TODO @j-sentinel:同 JobLogMapper 的一些优化点
|
||||
Integer jobCleanErrorLog(@Param("errorLogJobDay") Integer errorLogJobDay);
|
||||
|
||||
void optimizeTable();
|
||||
|
@ -52,10 +52,13 @@ public class JobLogServiceImpl implements JobLogService {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO @j-sentinel:这个 job,也可以忽略租户哈;可以直接使用 @TenantIgnore 注解;
|
||||
@Override
|
||||
public Integer timingJobCleanLog(Integer jobCleanRetainDay) {
|
||||
Integer result = null;
|
||||
int count = 0;
|
||||
// TODO @j-sentinel:一般我们在写逻辑时,尽量避免用 while true 这种“死循环”,而是 for (int i = 0; i < Short.MAX) 类似这种;避免里面真的发生一些意外的情况,无限执行;
|
||||
// 然后 for 里面,可以有个 if count < 100 未到达删除的预期条数,说明已经到底,可以 break 了;
|
||||
while (result == null || DELETE_LIMIT.equals(result)){
|
||||
result = jobLogMapper.timingJobCleanLog(jobCleanRetainDay);
|
||||
count += result;
|
||||
|
@ -47,6 +47,7 @@ public class ApiAccessLogServiceImpl implements ApiAccessLogService {
|
||||
}
|
||||
|
||||
@Override
|
||||
// TODO j-sentinel:类似 JobLogServiceImpl 的建议
|
||||
public void jobCleanAccessLog(Integer accessLogJobDay) {
|
||||
TenantUtils.executeIgnore(() -> {
|
||||
Integer result = null;
|
||||
|
@ -68,6 +68,7 @@ public class ApiErrorLogServiceImpl implements ApiErrorLogService {
|
||||
}
|
||||
|
||||
@Override
|
||||
// TODO j-sentinel:类似 JobLogServiceImpl 的建议
|
||||
public void jobCleanErrorLog(Integer errorLogJobDay) {
|
||||
TenantUtils.executeIgnore(() -> {
|
||||
Integer result = null;
|
||||
|
Reference in New Issue
Block a user