job日志记录入库
This commit is contained in:
+5
@@ -23,7 +23,10 @@ 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.Insert;
|
||||
import fun.asgc.neutrino.core.db.mapper.SqlMapper;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.JobInfoDO;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.JobLogDO;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -34,4 +37,6 @@ import fun.asgc.neutrino.core.db.mapper.SqlMapper;
|
||||
@Component
|
||||
public interface JobLogMapper extends SqlMapper {
|
||||
|
||||
@Insert("insert into job_log(`job_id`,`handler`,`param`,`code`,`msg`,`alarm_status`,`create_time`) values(:jobId,:handler,:param,:code,:msg,:alarmStatus,:createTime)")
|
||||
void add(JobLogDO jobLog);
|
||||
}
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ import java.util.Date;
|
||||
@Accessors(chain = true)
|
||||
@Data
|
||||
@Table("job_log")
|
||||
public class JobLog {
|
||||
public class JobLogDO {
|
||||
@Autowired
|
||||
private Integer id;
|
||||
private Integer jobId;
|
||||
+22
@@ -21,11 +21,17 @@
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.service;
|
||||
|
||||
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.IJobCallback;
|
||||
import fun.asgc.neutrino.core.quartz.JobInfo;
|
||||
import fun.asgc.neutrino.proxy.server.dal.JobLogMapper;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.JobLogDO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -36,14 +42,30 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@NonIntercept
|
||||
@Component
|
||||
public class JobLogService implements IJobCallback {
|
||||
@Autowired
|
||||
private JobLogMapper jobLogMapper;
|
||||
|
||||
@Override
|
||||
public void executeLog(JobInfo jobInfo, Throwable throwable) {
|
||||
Integer code = 0;
|
||||
String msg = "";
|
||||
if (null == throwable) {
|
||||
msg = "执行成功";
|
||||
log.info("job[id={},name={}]执行完毕", jobInfo.getId(), jobInfo.getName());
|
||||
} else {
|
||||
log.error("job[id={},name={}]执行异常", jobInfo.getId(), jobInfo.getName(), throwable);
|
||||
msg = "执行异常:\r\n" + ExceptionUtils.getStackTrace(throwable);
|
||||
code = -1;
|
||||
}
|
||||
jobLogMapper.add(new JobLogDO()
|
||||
.setJobId(Integer.valueOf(jobInfo.getId()))
|
||||
.setHandler(jobInfo.getName())
|
||||
.setParam(jobInfo.getParam())
|
||||
.setCode(code)
|
||||
.setMsg(msg)
|
||||
.setAlarmStatus(0)
|
||||
.setCreateTime(new Date())
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user