新增数据清理job,更新初始化sql脚本
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
package fun.asgc.neutrino.proxy.server.dal;
|
||||
|
||||
import fun.asgc.neutrino.core.annotation.Component;
|
||||
import fun.asgc.neutrino.core.aop.Intercept;
|
||||
import fun.asgc.neutrino.core.db.annotation.Delete;
|
||||
import fun.asgc.neutrino.core.db.mapper.SqlMapper;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/9/17
|
||||
*/
|
||||
@Intercept(ignoreGlobal = true)
|
||||
@Component
|
||||
public interface DataCleanMapper extends SqlMapper {
|
||||
|
||||
@Delete("delete from `job_log` where create_time < ?")
|
||||
void cleanJobLog(Date date);
|
||||
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package fun.asgc.neutrino.proxy.server.job;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import fun.asgc.neutrino.core.annotation.Autowired;
|
||||
import fun.asgc.neutrino.core.annotation.Component;
|
||||
import fun.asgc.neutrino.core.annotation.NonIntercept;
|
||||
import fun.asgc.neutrino.core.quartz.IJobHandler;
|
||||
import fun.asgc.neutrino.core.quartz.annotation.JobHandler;
|
||||
import fun.asgc.neutrino.core.util.DateUtil;
|
||||
import fun.asgc.neutrino.proxy.server.dal.DataCleanMapper;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 日志清理Job
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/9/17
|
||||
*/
|
||||
@Slf4j
|
||||
@NonIntercept
|
||||
@Component
|
||||
@JobHandler(name = "DataCleanJob", cron = "0 0 1 * * ?")
|
||||
public class DataCleanJob implements IJobHandler {
|
||||
@Autowired
|
||||
private DataCleanMapper dataCleanMapper;
|
||||
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
/**
|
||||
* Job日志保存天数
|
||||
*/
|
||||
private static final Integer JOB_LOG_KEEP_DAYS = 7;
|
||||
|
||||
@Override
|
||||
public void execute(String s) throws Exception {
|
||||
JobParams jobParams = getParams(s);
|
||||
|
||||
Date date = DateUtil.addDate(new Date(), Calendar.DATE, jobParams.getJobLogKeepDays());
|
||||
log.info("清理调度管理日志 date:{}", sdf.format(date));
|
||||
dataCleanMapper.cleanJobLog(date);
|
||||
}
|
||||
|
||||
public static JobParams getParams(String s) {
|
||||
try {
|
||||
return JSONObject.parseObject(s, JobParams.class);
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
return new JobParams()
|
||||
.setJobLogKeepDays(JOB_LOG_KEEP_DAYS);
|
||||
}
|
||||
|
||||
@Accessors(chain = true)
|
||||
@Data
|
||||
public static class JobParams {
|
||||
private Integer jobLogKeepDays;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
#job_qrtz_trigger_info
|
||||
insert into job_info(`id`, `desc`, `handler`, `cron`, `param`, `enable`, `create_time`, `update_time`) values
|
||||
(1, '示例Job', 'DemoJob', '0/10 * * * * ?', '{"a":101}', 1, STRFTIME('%s000', 'NOW'), STRFTIME('%s000', 'NOW'));
|
||||
insert into job_info(`id`, `desc`, `handler`, `cron`, `param`, `enable`, `create_time`, `update_time`) values
|
||||
(2, '数据清理任务', 'DataCleanJob', '0 0 1 * * ?', '', 1, STRFTIME('%s000', 'NOW'), STRFTIME('%s000', 'NOW'));
|
||||
@@ -1 +0,0 @@
|
||||
#job_qrtz_trigger_info
|
||||
Reference in New Issue
Block a user