增加定时清理日志线程

This commit is contained in:
18188916393
2022-08-10 09:26:07 +08:00
parent e30433e2bd
commit b243cfd895
2 changed files with 37 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
package org.nl.modules.quartz.task;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.wql.core.bean.WQLObject;
import org.springframework.stereotype.Component;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* @author geng by
* 自动清理大于十五天的日志
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class AutoCleanUpLogs {
private ExecutorService threadPool = Executors.newCachedThreadPool();
public void run() throws Exception {
try {
System.out.println("开始清理日志");
// 0 0/10 0,1 * * ? * 每天0-1点执行间隔10分钟一次
//sys_log
//delete from sys_log where DATE(create_time) <= DATE(DATE_SUB(NOW(),INTERVAL 30 day)) limit 10;
WQLObject logTab = WQLObject.getWQLObject("sys_log");
String days = WQLObject.getWQLObject("sys_param").query("code='clean_day'").uniqueResult(0).getString("value");
logTab.delete("DATE(create_time) <= DATE(DATE_SUB(NOW(),INTERVAL '" + days + "' day)) limit 500");
log.info("自动清理日志执行成功...!");
} catch (Exception e) {
e.printStackTrace();
}
}
}