|
@@ -0,0 +1,108 @@
|
|
|
+package cn.com.qmth.examcloud.core.oe.task.starter.config;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.commons.exception.ExamCloudRuntimeException;
|
|
|
+import cn.com.qmth.examcloud.commons.helpers.pipeline.Node;
|
|
|
+import cn.com.qmth.examcloud.commons.helpers.pipeline.SimpleNode;
|
|
|
+import cn.com.qmth.examcloud.commons.helpers.pipeline.TaskContext;
|
|
|
+import cn.com.qmth.examcloud.core.oe.task.service.pipeline.AfterHandInExamExecutor;
|
|
|
+import cn.com.qmth.examcloud.core.oe.task.service.pipeline.DataGainExamExecutor;
|
|
|
+import cn.com.qmth.examcloud.core.oe.task.service.pipeline.HandInExamExecutor;
|
|
|
+import cn.com.qmth.examcloud.core.oe.task.service.pipeline.SyncExamDataExecutor;
|
|
|
+import cn.com.qmth.examcloud.support.cache.CacheHelper;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.SysPropertyCacheBean;
|
|
|
+import cn.com.qmth.examcloud.support.examing.ExamRecordData;
|
|
|
+import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.boot.ApplicationArguments;
|
|
|
+import org.springframework.boot.ApplicationRunner;
|
|
|
+import org.springframework.cloud.client.ServiceInstance;
|
|
|
+import org.springframework.cloud.client.discovery.DiscoveryClient;
|
|
|
+import org.springframework.core.annotation.Order;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description 流式任务执行器
|
|
|
+ * @Author lideyin
|
|
|
+ * @Date 2019/12/24 15:52
|
|
|
+ * @Version 1.0
|
|
|
+ */
|
|
|
+@Component
|
|
|
+@Order(300)
|
|
|
+public class StreamTaskExecutor implements ApplicationRunner {
|
|
|
+ @Autowired
|
|
|
+ private DataGainExamExecutor dataGainExamExecutor;
|
|
|
+ @Autowired
|
|
|
+ HandInExamExecutor handInExamExecutor;
|
|
|
+ @Autowired
|
|
|
+ AfterHandInExamExecutor afterHandInExamExecutor;
|
|
|
+ @Autowired
|
|
|
+ SyncExamDataExecutor syncExamDataExecutor;
|
|
|
+
|
|
|
+ private static Integer DEFAULT_GAIN_EXAM_DATA_EXECUTOR_SLEEP_SECONDS = 30;
|
|
|
+ private static Integer DEFAULT_HAND_IN_EXAM_EXECUTOR_SLEEP_SECONDS = 5 * 60;
|
|
|
+ private static Integer DEFAULT_AFTER_HAND_IN_EXAM_EXECUTOR_SLEEP_SECONDS = 5;
|
|
|
+ private static Integer DEFAULT_SYNC_EXAM_DATA_EXECUTOR_SLEEP_SECONDS = 5;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void run(ApplicationArguments args) throws Exception {
|
|
|
+ initExecutor();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initExecutor() {
|
|
|
+ TaskContext context = new TaskContext();
|
|
|
+
|
|
|
+ Node<Long, ExamRecordData, Long, ExamRecordData> node1 = new SimpleNode<>(
|
|
|
+ "gainExamData", dataGainExamExecutor, context);
|
|
|
+
|
|
|
+ Node<Long, ExamRecordData, Long, ExamRecordData> node2 = new SimpleNode<>(
|
|
|
+ "handInExam", handInExamExecutor, context);
|
|
|
+
|
|
|
+ Node<Long, ExamRecordData, Long, ExamRecordData> node3 = new SimpleNode<>(
|
|
|
+ "afterHandInExam", afterHandInExamExecutor, context);
|
|
|
+
|
|
|
+ Node<Long, ExamRecordData, Long, ExamRecordData> node4 = new SimpleNode<>(
|
|
|
+ "syncExamData", syncExamDataExecutor, context);
|
|
|
+
|
|
|
+ node1.setFirst(true);
|
|
|
+ node1.setLowerNode(node2);
|
|
|
+ SysPropertyCacheBean node1SleepProperty = CacheHelper.getSysProperty("oeTask.executor.gainExamData.sleep");
|
|
|
+ if (node1SleepProperty.getHasValue()) {
|
|
|
+ node1.setSleep(Integer.valueOf(node1SleepProperty.getValue().toString()));//单位秒
|
|
|
+ } else {
|
|
|
+ node1.setSleep(DEFAULT_GAIN_EXAM_DATA_EXECUTOR_SLEEP_SECONDS);//单位秒
|
|
|
+ }
|
|
|
+
|
|
|
+ node2.setLowerNode(node3);
|
|
|
+ SysPropertyCacheBean node2SleepProperty = CacheHelper.getSysProperty("oeTask.executor.handInExam.sleep");
|
|
|
+ if (node2SleepProperty.getHasValue()) {
|
|
|
+ node2.setSleep(Integer.valueOf(node2SleepProperty.getValue().toString()));//单位秒
|
|
|
+ } else {
|
|
|
+ node2.setSleep(DEFAULT_HAND_IN_EXAM_EXECUTOR_SLEEP_SECONDS);//单位秒
|
|
|
+ }
|
|
|
+
|
|
|
+ node3.setLowerNode(node4);
|
|
|
+ SysPropertyCacheBean node3SleepProperty = CacheHelper.getSysProperty("oeTask.executor.afterHandInExam.sleep");
|
|
|
+ if (node3SleepProperty.getHasValue()) {
|
|
|
+ node3.setSleep(Integer.valueOf(node3SleepProperty.getValue().toString()));//单位秒
|
|
|
+ } else {
|
|
|
+ node3.setSleep(DEFAULT_AFTER_HAND_IN_EXAM_EXECUTOR_SLEEP_SECONDS);//单位秒
|
|
|
+ }
|
|
|
+
|
|
|
+ SysPropertyCacheBean node4SleepProperty = CacheHelper.getSysProperty("oeTask.executor.syncExamData.sleep");
|
|
|
+ if (node4SleepProperty.getHasValue()) {
|
|
|
+ node4.setSleep(Integer.valueOf(node4SleepProperty.getValue().toString()));//单位秒
|
|
|
+ } else {
|
|
|
+ node4.setSleep(DEFAULT_SYNC_EXAM_DATA_EXECUTOR_SLEEP_SECONDS);//单位秒
|
|
|
+ }
|
|
|
+
|
|
|
+ node1.start();
|
|
|
+ node2.start();
|
|
|
+ node3.start();
|
|
|
+ node4.start();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|