wangwei 7 роки тому
батько
коміт
3669eaf863

+ 59 - 61
examcloud-task-base/src/main/java/cn/com/qmth/examcloud/task/base/AbstractTask.java

@@ -1,61 +1,59 @@
-package cn.com.qmth.examcloud.task.base;
-
-import org.quartz.JobExecutionContext;
-
-import cn.com.qmth.examcloud.commons.base.exception.ExamCloudRuntimeException;
-import cn.com.qmth.examcloud.commons.base.logging.ExamCloudLog;
-import cn.com.qmth.examcloud.commons.base.logging.ExamCloudLogFactory;
-import cn.com.qmth.examcloud.commons.base.util.JsonUtil;
-
-/**
- * 任务调度抽象类
- *
- * @author WANGWEI
- * @date 2018年3月7日
- * @Copyright (c) 2018-2020 WANGWEI [QQ:522080330] All Rights Reserved.
- */
-public abstract class AbstractTask implements Task {
-
-	protected ExamCloudLog taskLog = ExamCloudLogFactory.getLog("TASK_LOGGER");
-
-	protected ExamCloudLog debugLog = ExamCloudLogFactory.getLog(this.getClass());
-
-	public abstract TaskTracker getTaskTracker();
-
-	public abstract void run(ScheduleJob scheduleJob) throws Exception;
-
-	@Override
-	public void execute(JobExecutionContext context, ScheduleJob scheduleJob, String traceId) {
-		try {
-			getTaskTracker().start(context, scheduleJob, traceId);
-		} catch (Exception e) {
-			taskLog.error("[TASK TRACKER]. start", e);
-		}
-		if (taskLog.isDebugEnabled()) {
-			taskLog.debug("[TASK IN]. detail: " + JsonUtil.toJson(scheduleJob));
-		}
-		try {
-			run(scheduleJob);
-		} catch (Exception e) {
-			try {
-				getTaskTracker().whenException(context, scheduleJob, traceId, e);
-			} catch (Exception ex) {
-				taskLog.error("[TASK TRACKER]. whenException", ex);
-			}
-			if (taskLog.isErrorEnabled()) {
-				taskLog.error("[TASK EXCEPTION]. detail: " + JsonUtil.toJson(scheduleJob), e);
-			}
-			throw new ExamCloudRuntimeException(e);
-		}
-		try {
-			getTaskTracker().onEnd(context, scheduleJob, traceId);
-		} catch (Exception e) {
-			taskLog.error("[TASK TRACKER]. onEnd", e);
-		}
-		if (taskLog.isDebugEnabled()) {
-			taskLog.debug("[TASK OUT]. detail: " + JsonUtil.toJson(scheduleJob));
-		}
-
-	}
-
-}
+package cn.com.qmth.examcloud.task.base;
+
+import cn.com.qmth.examcloud.commons.base.exception.ExamCloudRuntimeException;
+import cn.com.qmth.examcloud.commons.base.logging.ExamCloudLog;
+import cn.com.qmth.examcloud.commons.base.logging.ExamCloudLogFactory;
+import cn.com.qmth.examcloud.commons.base.util.JsonUtil;
+
+/**
+ * 任务调度抽象类
+ *
+ * @author WANGWEI
+ * @date 2018年3月7日
+ * @Copyright (c) 2018-2020 WANGWEI [QQ:522080330] All Rights Reserved.
+ */
+public abstract class AbstractTask implements Task {
+
+	protected ExamCloudLog taskLog = ExamCloudLogFactory.getLog("TASK_LOGGER");
+
+	protected ExamCloudLog debugLog = ExamCloudLogFactory.getLog(this.getClass());
+
+	public abstract TaskTracker getTaskTracker();
+
+	public abstract void run(ScheduleJob scheduleJob) throws Exception;
+
+	@Override
+	public void execute(ScheduleJob scheduleJob, String traceId) {
+		try {
+			getTaskTracker().start(scheduleJob, traceId);
+		} catch (Exception e) {
+			taskLog.error("[TASK TRACKER]. start", e);
+		}
+		if (taskLog.isDebugEnabled()) {
+			taskLog.debug("[TASK IN]. detail: " + JsonUtil.toJson(scheduleJob));
+		}
+		try {
+			run(scheduleJob);
+		} catch (Exception e) {
+			try {
+				getTaskTracker().whenException(scheduleJob, traceId, e);
+			} catch (Exception ex) {
+				taskLog.error("[TASK TRACKER]. whenException", ex);
+			}
+			if (taskLog.isErrorEnabled()) {
+				taskLog.error("[TASK EXCEPTION]. detail: " + JsonUtil.toJson(scheduleJob), e);
+			}
+			throw new ExamCloudRuntimeException(e);
+		}
+		try {
+			getTaskTracker().onEnd(scheduleJob, traceId);
+		} catch (Exception e) {
+			taskLog.error("[TASK TRACKER]. onEnd", e);
+		}
+		if (taskLog.isDebugEnabled()) {
+			taskLog.debug("[TASK OUT]. detail: " + JsonUtil.toJson(scheduleJob));
+		}
+
+	}
+
+}

+ 47 - 47
examcloud-task-base/src/main/java/cn/com/qmth/examcloud/task/base/DistributionJob.java

@@ -1,47 +1,47 @@
-package cn.com.qmth.examcloud.task.base;
-
-import org.quartz.Job;
-import org.quartz.JobExecutionContext;
-import org.quartz.JobExecutionException;
-
-import cn.com.qmth.examcloud.commons.base.logging.ExamCloudLog;
-import cn.com.qmth.examcloud.commons.base.logging.ExamCloudLogFactory;
-import cn.com.qmth.examcloud.commons.base.util.JsonUtil;
-import cn.com.qmth.examcloud.commons.base.util.ThreadLocalUtil;
-import cn.com.qmth.examcloud.commons.web.support.SpringContextHolder;
-
-/**
- * 并行任务分发器
- *
- * @author WANGWEI
- * @date 2018年3月7日
- * @Copyright (c) 2018-2020 WANGWEI [QQ:522080330] All Rights Reserved.
- */
-public class DistributionJob implements Job {
-	private static final ExamCloudLog TASK_LOG = ExamCloudLogFactory.getLog("TASK_LOGGER");
-
-	@Override
-	public void execute(JobExecutionContext context) throws JobExecutionException {
-		String traceId = ThreadLocalUtil.next();
-		ScheduleJob scheduleJob = (ScheduleJob) context.getMergedJobDataMap().get("scheduleJob");
-
-		if (TASK_LOG.isDebugEnabled()) {
-			TASK_LOG.debug("distribute job. job detail :" + JsonUtil.toJson(scheduleJob));
-		}
-
-		try {
-			Object bean = SpringContextHolder.getBean(scheduleJob.getSpringBean());
-
-			Task task = (Task) bean;
-			task.execute(context, scheduleJob, traceId);
-		} catch (Exception e) {
-			if (TASK_LOG.isErrorEnabled()) {
-				TASK_LOG.error(
-						"fail to distribute job. job detail :" + JsonUtil.toJson(scheduleJob), e);
-			}
-			throw new JobExecutionException(e);
-		}
-
-	}
-
-}
+package cn.com.qmth.examcloud.task.base;
+
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+
+import cn.com.qmth.examcloud.commons.base.logging.ExamCloudLog;
+import cn.com.qmth.examcloud.commons.base.logging.ExamCloudLogFactory;
+import cn.com.qmth.examcloud.commons.base.util.JsonUtil;
+import cn.com.qmth.examcloud.commons.base.util.ThreadLocalUtil;
+import cn.com.qmth.examcloud.commons.web.support.SpringContextHolder;
+
+/**
+ * 并行任务分发器
+ *
+ * @author WANGWEI
+ * @date 2018年3月7日
+ * @Copyright (c) 2018-2020 WANGWEI [QQ:522080330] All Rights Reserved.
+ */
+public class DistributionJob implements Job {
+	private static final ExamCloudLog TASK_LOG = ExamCloudLogFactory.getLog("TASK_LOGGER");
+
+	@Override
+	public void execute(JobExecutionContext context) throws JobExecutionException {
+		String traceId = ThreadLocalUtil.next();
+		ScheduleJob scheduleJob = (ScheduleJob) context.getMergedJobDataMap().get("scheduleJob");
+
+		if (TASK_LOG.isDebugEnabled()) {
+			TASK_LOG.debug("distribute job. job detail :" + JsonUtil.toJson(scheduleJob));
+		}
+
+		try {
+			Object bean = SpringContextHolder.getBean(scheduleJob.getSpringBean());
+
+			Task task = (Task) bean;
+			task.execute(scheduleJob, traceId);
+		} catch (Exception e) {
+			if (TASK_LOG.isErrorEnabled()) {
+				TASK_LOG.error(
+						"fail to distribute job. job detail :" + JsonUtil.toJson(scheduleJob), e);
+			}
+			throw new JobExecutionException(e);
+		}
+
+	}
+
+}

+ 20 - 22
examcloud-task-base/src/main/java/cn/com/qmth/examcloud/task/base/Task.java

@@ -1,22 +1,20 @@
-package cn.com.qmth.examcloud.task.base;
-
-import org.quartz.JobExecutionContext;
-
-/**
- * 任务接口
- *
- * @author WANGWEI
- * @date 2018年3月7日
- * @Copyright (c) 2018-2020 WANGWEI [QQ:522080330] All Rights Reserved.
- */
-public interface Task {
-
-	/**
-	 * 执行任务
-	 *
-	 * @author WANGWEI
-	 * @param scheduleJob
-	 * @param traceId
-	 */
-	void execute(JobExecutionContext context, ScheduleJob scheduleJob, String traceId);
-}
+package cn.com.qmth.examcloud.task.base;
+
+/**
+ * 任务接口
+ *
+ * @author WANGWEI
+ * @date 2018年3月7日
+ * @Copyright (c) 2018-2020 WANGWEI [QQ:522080330] All Rights Reserved.
+ */
+public interface Task {
+
+	/**
+	 * 执行任务
+	 *
+	 * @author WANGWEI
+	 * @param scheduleJob
+	 * @param traceId
+	 */
+	void execute(ScheduleJob scheduleJob, String traceId);
+}

+ 40 - 43
examcloud-task-base/src/main/java/cn/com/qmth/examcloud/task/base/TaskTracker.java

@@ -1,43 +1,40 @@
-package cn.com.qmth.examcloud.task.base;
-
-import org.quartz.JobExecutionContext;
-
-/**
- * 任务跟踪记载器
- *
- * @author WANGWEI
- * @date 2018年7月25日
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
- */
-public interface TaskTracker {
-
-	/**
-	 * 启动
-	 *
-	 * @author WANGWEI
-	 * @param scheduleJob
-	 * @param traceId
-	 */
-	void start(JobExecutionContext context, final ScheduleJob scheduleJob, final String traceId);
-
-	/**
-	 * 异常
-	 *
-	 * @author WANGWEI
-	 * @param scheduleJob
-	 * @param traceId
-	 * @param e
-	 */
-	void whenException(JobExecutionContext context, final ScheduleJob scheduleJob,
-			final String traceId, Exception e);
-
-	/**
-	 * 结束
-	 *
-	 * @author WANGWEI
-	 * @param scheduleJob
-	 * @param traceId
-	 */
-	void onEnd(JobExecutionContext context, final ScheduleJob scheduleJob, final String traceId);
-
-}
+package cn.com.qmth.examcloud.task.base;
+
+/**
+ * 任务跟踪记载器
+ *
+ * @author WANGWEI
+ * @date 2018年7月25日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public interface TaskTracker {
+
+	/**
+	 * 启动
+	 *
+	 * @author WANGWEI
+	 * @param scheduleJob
+	 * @param traceId
+	 */
+	void start(final ScheduleJob scheduleJob, final String traceId);
+
+	/**
+	 * 异常
+	 *
+	 * @author WANGWEI
+	 * @param scheduleJob
+	 * @param traceId
+	 * @param e
+	 */
+	void whenException(final ScheduleJob scheduleJob, final String traceId, Exception e);
+
+	/**
+	 * 结束
+	 *
+	 * @author WANGWEI
+	 * @param scheduleJob
+	 * @param traceId
+	 */
+	void onEnd(final ScheduleJob scheduleJob, final String traceId);
+
+}

+ 59 - 61
examcloud-task-service/src/main/java/cn/com/qmth/examcloud/task/service/DefaultTaskTracker.java

@@ -1,61 +1,59 @@
-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);
-
-	}
-
-}
+package cn.com.qmth.examcloud.task.service;
+
+import java.util.Date;
+
+import javax.transaction.Transactional;
+
+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(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(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(ScheduleJob scheduleJob, String traceId) {
+		TaskTraceEntity entity = taskTraceRepo.findByTraceId(traceId);
+		entity.setJobStatus("成功");
+		entity.setEndTime(new Date());
+		taskTraceRepo.save(entity);
+
+	}
+
+}