mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
添加删除数据采集器的定时任务
This commit is contained in:
@@ -15,6 +15,9 @@ import cn.lihongjie.coal.dataCollectorLog.mapper.DataCollectorLogMapper;
|
||||
import cn.lihongjie.coal.dataCollectorLog.repository.DataCollectorLogRepository;
|
||||
import cn.lihongjie.coal.dbFunctions.DbFunctionService;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
@@ -75,5 +78,22 @@ public class DataCollectorLogService
|
||||
Sort.by(CollectionUtils.isEmpty(query.getOrders()) ? singletonList(asc("createTime")) : query.getOrders())));
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
}
|
||||
|
||||
@PersistenceContext EntityManager em;
|
||||
|
||||
public void deleteHisLog(){
|
||||
|
||||
|
||||
// 只保留最近3个月的日志
|
||||
|
||||
int cnt = em.createNativeQuery("delete from t_data_collector_log where create_time < now() - interval '3 month'").executeUpdate();
|
||||
|
||||
log.info("delete {} data collector his log", cnt);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import cn.lihongjie.coal.dataCollectorLog.service.DataCollectorLogService
|
||||
import org.springframework.context.ApplicationContext
|
||||
|
||||
ApplicationContext ioc = ioc
|
||||
|
||||
def service = ioc.getBean(DataCollectorLogService.class)
|
||||
|
||||
service.deleteHisLog()
|
||||
|
||||
Reference in New Issue
Block a user