增加定时清理日志线程
This commit is contained in:
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
Reference in New Issue
Block a user