|
@@ -0,0 +1,61 @@
|
|
|
+package cn.com.qmth.examcloud.task.service;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
+import javax.transaction.Transactional;
|
|
|
+
|
|
|
+import org.quartz.JobExecutionContext;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.task.base.ScheduleJob;
|
|
|
+import cn.com.qmth.examcloud.task.base.TaskTracker;
|
|
|
+import cn.com.qmth.examcloud.task.dao.TaskTraceRepo;
|
|
|
+import cn.com.qmth.examcloud.task.dao.entity.TaskTraceEntity;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 类注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @date 2018年7月25日
|
|
|
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class DefaultTaskTracker implements TaskTracker {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ TaskTraceRepo taskTraceRepo;
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public void start(JobExecutionContext context, ScheduleJob scheduleJob, String traceId) {
|
|
|
+ TaskTraceEntity entity = new TaskTraceEntity();
|
|
|
+ entity.setJobId(scheduleJob.getJobId());
|
|
|
+ entity.setStartTime(new Date());
|
|
|
+ entity.setTraceId(traceId);
|
|
|
+ entity.setJobStatus("启动");
|
|
|
+ taskTraceRepo.save(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public void whenException(JobExecutionContext context, ScheduleJob scheduleJob, String traceId,
|
|
|
+ Exception e) {
|
|
|
+ TaskTraceEntity entity = taskTraceRepo.findByTraceId(traceId);
|
|
|
+ entity.setJobStatus("异常");
|
|
|
+ entity.setEndTime(new Date());
|
|
|
+ entity.setException(e.getCause().getMessage());
|
|
|
+ taskTraceRepo.save(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public void onEnd(JobExecutionContext context, ScheduleJob scheduleJob, String traceId) {
|
|
|
+ TaskTraceEntity entity = taskTraceRepo.findByTraceId(traceId);
|
|
|
+ entity.setJobStatus("成功");
|
|
|
+ entity.setEndTime(new Date());
|
|
|
+ taskTraceRepo.save(entity);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|