|
@@ -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));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|