修复调度任务手动出发执行相关bug
This commit is contained in:
@@ -54,6 +54,7 @@ public class DefaultJobSource implements IJobSource {
|
|||||||
.setDesc(handler.desc())
|
.setDesc(handler.desc())
|
||||||
.setCron(handler.cron())
|
.setCron(handler.cron())
|
||||||
.setParam(handler.param())
|
.setParam(handler.param())
|
||||||
|
.setEnable(true)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return jobInfoList;
|
return jobInfoList;
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ public interface IJobCallback {
|
|||||||
/**
|
/**
|
||||||
* 执行日志
|
* 执行日志
|
||||||
* @param jobInfo
|
* @param jobInfo
|
||||||
|
* @param param
|
||||||
* @param throwable
|
* @param throwable
|
||||||
*/
|
*/
|
||||||
void executeLog(JobInfo jobInfo, Throwable throwable);
|
void executeLog(JobInfo jobInfo, String param, Throwable throwable);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ public class JobExecutor implements ApplicationRunner, IJobExecutor {
|
|||||||
@Override
|
@Override
|
||||||
public void add(JobInfo jobInfo) throws JobException {
|
public void add(JobInfo jobInfo) throws JobException {
|
||||||
if (null == jobInfo || StringUtil.isEmpty(jobInfo.getId()) || StringUtil.isEmpty(jobInfo.getName()) ||
|
if (null == jobInfo || StringUtil.isEmpty(jobInfo.getId()) || StringUtil.isEmpty(jobInfo.getName()) ||
|
||||||
StringUtil.isEmpty(jobInfo.getCron()) || runJobSet.contains(jobInfo.getName())) {
|
StringUtil.isEmpty(jobInfo.getCron())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
synchronized (jobInfo.getId()) {
|
synchronized (jobInfo.getId()) {
|
||||||
@@ -128,8 +128,10 @@ public class JobExecutor implements ApplicationRunner, IJobExecutor {
|
|||||||
JobDetail jobDetail = JobBuilder.newJob(JobBean.class).withIdentity(jobKey).build();
|
JobDetail jobDetail = JobBuilder.newJob(JobBean.class).withIdentity(jobKey).build();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
scheduler.scheduleJob(jobDetail, cronTrigger);
|
if (jobInfo.isEnable()) {
|
||||||
scheduler.start();
|
scheduler.scheduleJob(jobDetail, cronTrigger);
|
||||||
|
scheduler.start();
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(String.format("新增job[name=%s]异常", jobInfo.getName()));
|
throw new RuntimeException(String.format("新增job[name=%s]异常", jobInfo.getName()));
|
||||||
}
|
}
|
||||||
@@ -190,10 +192,10 @@ public class JobExecutor implements ApplicationRunner, IJobExecutor {
|
|||||||
try {
|
try {
|
||||||
jobHandler.execute(param);
|
jobHandler.execute(param);
|
||||||
if (null != jobCallback) {
|
if (null != jobCallback) {
|
||||||
jobCallback.executeLog(jobInfo, null);
|
jobCallback.executeLog(jobInfo, param, null);
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
jobCallback.executeLog(jobInfo, e);
|
jobCallback.executeLog(jobInfo, param, e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,5 +39,6 @@ public class JobInfo {
|
|||||||
private String desc;
|
private String desc;
|
||||||
private String cron;
|
private String cron;
|
||||||
private String param;
|
private String param;
|
||||||
|
private boolean enable;
|
||||||
private Map<String, Object> extension;
|
private Map<String, Object> extension;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
public class JobCallback implements IJobCallback {
|
public class JobCallback implements IJobCallback {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void executeLog(JobInfo jobInfo, Throwable throwable) {
|
public void executeLog(JobInfo jobInfo, String param, Throwable throwable) {
|
||||||
if (null == throwable) {
|
if (null == throwable) {
|
||||||
log.info("job[name={}]执行完毕", jobInfo.getId(), jobInfo.getName());
|
log.info("job[name={}]执行完毕", jobInfo.getId(), jobInfo.getName());
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+1
-1
@@ -16,6 +16,6 @@ import java.util.Date;
|
|||||||
public interface DataCleanMapper extends SqlMapper {
|
public interface DataCleanMapper extends SqlMapper {
|
||||||
|
|
||||||
@Delete("delete from `job_log` where create_time < ?")
|
@Delete("delete from `job_log` where create_time < ?")
|
||||||
void cleanJobLog(Date date);
|
void cleanJobLog(long date);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -56,8 +56,8 @@ public interface JobInfoMapper extends SqlMapper {
|
|||||||
void updateEnableStatus(@Param("id") Integer id, @Param("enable") Integer enable, @Param("updateTime") Date updateTime);
|
void updateEnableStatus(@Param("id") Integer id, @Param("enable") Integer enable, @Param("updateTime") Date updateTime);
|
||||||
|
|
||||||
@ResultType(JobInfoDO.class)
|
@ResultType(JobInfoDO.class)
|
||||||
@Select("select * from job_info where enable = 1")
|
@Select("select * from job_info")
|
||||||
List<JobInfoDO> findEnableList();
|
List<JobInfoDO> findList();
|
||||||
|
|
||||||
void update(JobInfoDO jobInfoDO);
|
void update(JobInfoDO jobInfoDO);
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-3
@@ -11,6 +11,7 @@ import fun.asgc.neutrino.proxy.server.dal.DataCleanMapper;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
@@ -38,14 +39,16 @@ public class DataCleanJob implements IJobHandler {
|
|||||||
public void execute(String s) throws Exception {
|
public void execute(String s) throws Exception {
|
||||||
JobParams jobParams = getParams(s);
|
JobParams jobParams = getParams(s);
|
||||||
|
|
||||||
Date date = DateUtil.addDate(new Date(), Calendar.DATE, jobParams.getJobLogKeepDays());
|
Date date = DateUtil.addDate(new Date(), Calendar.DATE, -1 * jobParams.getJobLogKeepDays());
|
||||||
log.info("清理调度管理日志 date:{}", sdf.format(date));
|
log.info("清理调度管理日志 date:{}", sdf.format(date));
|
||||||
dataCleanMapper.cleanJobLog(date);
|
dataCleanMapper.cleanJobLog(date.getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JobParams getParams(String s) {
|
public static JobParams getParams(String s) {
|
||||||
try {
|
try {
|
||||||
return JSONObject.parseObject(s, JobParams.class);
|
if (StringUtils.isNotBlank(s)) {
|
||||||
|
return JSONObject.parseObject(s, JobParams.class);
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -74,6 +74,7 @@ public class JobInfoService implements IJobSource {
|
|||||||
.setDesc(jobInfoDO.getDesc())
|
.setDesc(jobInfoDO.getDesc())
|
||||||
.setCron(jobInfoDO.getCron())
|
.setCron(jobInfoDO.getCron())
|
||||||
.setParam(jobInfoDO.getParam())
|
.setParam(jobInfoDO.getParam())
|
||||||
|
.setEnable(true)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
BeanManager.getBean(JobExecutor.class).remove(String.valueOf(req.getId()));
|
BeanManager.getBean(JobExecutor.class).remove(String.valueOf(req.getId()));
|
||||||
@@ -89,7 +90,7 @@ public class JobInfoService implements IJobSource {
|
|||||||
@Override
|
@Override
|
||||||
public List<JobInfo> sourceList() {
|
public List<JobInfo> sourceList() {
|
||||||
List<JobInfo> jobInfoList = Lists.newArrayList();
|
List<JobInfo> jobInfoList = Lists.newArrayList();
|
||||||
List<JobInfoDO> jobInfoDOList = jobInfoMapper.findEnableList();
|
List<JobInfoDO> jobInfoDOList = jobInfoMapper.findList();
|
||||||
if (CollectionUtil.isEmpty(jobInfoDOList)) {
|
if (CollectionUtil.isEmpty(jobInfoDOList)) {
|
||||||
return jobInfoList;
|
return jobInfoList;
|
||||||
}
|
}
|
||||||
@@ -100,6 +101,7 @@ public class JobInfoService implements IJobSource {
|
|||||||
.setDesc(item.getDesc())
|
.setDesc(item.getDesc())
|
||||||
.setCron(item.getCron())
|
.setCron(item.getCron())
|
||||||
.setParam(item.getParam())
|
.setParam(item.getParam())
|
||||||
|
.setEnable(EnableStatusEnum.ENABLE.getStatus().equals(item.getEnable()))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -46,7 +46,7 @@ public class JobLogService implements IJobCallback {
|
|||||||
private JobLogMapper jobLogMapper;
|
private JobLogMapper jobLogMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void executeLog(JobInfo jobInfo, Throwable throwable) {
|
public void executeLog(JobInfo jobInfo, String param, Throwable throwable) {
|
||||||
Integer code = 0;
|
Integer code = 0;
|
||||||
String msg = "";
|
String msg = "";
|
||||||
if (null == throwable) {
|
if (null == throwable) {
|
||||||
@@ -60,7 +60,7 @@ public class JobLogService implements IJobCallback {
|
|||||||
jobLogMapper.add(new JobLogDO()
|
jobLogMapper.add(new JobLogDO()
|
||||||
.setJobId(Integer.valueOf(jobInfo.getId()))
|
.setJobId(Integer.valueOf(jobInfo.getId()))
|
||||||
.setHandler(jobInfo.getName())
|
.setHandler(jobInfo.getName())
|
||||||
.setParam(jobInfo.getParam())
|
.setParam(param)
|
||||||
.setCode(code)
|
.setCode(code)
|
||||||
.setMsg(msg)
|
.setMsg(msg)
|
||||||
.setAlarmStatus(0)
|
.setAlarmStatus(0)
|
||||||
|
|||||||
Reference in New Issue
Block a user