chenken vor 7 Jahren
Ursprung
Commit
6591b5b65d

+ 13 - 0
examcloud-task-base/src/main/java/cn/com/qmth/task/base/ScheduleJob.java

@@ -47,6 +47,11 @@ public class ScheduleJob implements Serializable
 	 * 是否顺序执行
 	 */
 	private boolean stateful = true;
+	
+	/**
+	 * 随着容器启动而启动
+	 */
+	private boolean startWithContainer = false;
 
 	public String getJobName()
 	{
@@ -118,4 +123,12 @@ public class ScheduleJob implements Serializable
 		this.stateful = stateful;
 	}
 
+	public boolean isStartWithContainer() {
+		return startWithContainer;
+	}
+
+	public void setStartWithContainer(boolean startWithContainer) {
+		this.startWithContainer = startWithContainer;
+	}
+	
 }

+ 19 - 0
examcloud-task-dao/src/main/java/cn/com/qmth/task/entity/ScheduleJobEntity.java

@@ -3,6 +3,7 @@ package cn.com.qmth.task.entity;
 import java.io.Serializable;
 import java.util.Date;
 
+import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.GeneratedValue;
 import javax.persistence.Id;
@@ -76,6 +77,12 @@ public class ScheduleJobEntity implements Serializable
 	 */
 	private String operateResult;
 	
+	/**
+	 * 随着容器启动而启动
+	 */
+	@Column(name="start_width_container")
+	private Boolean startWithContainer;
+	
 	public String getJobName()
 	{
 		return jobName;
@@ -169,5 +176,17 @@ public class ScheduleJobEntity implements Serializable
 	public void setOperateResult(String operateResult) {
 		this.operateResult = operateResult;
 	}
+
+	public Boolean getStartWithContainer() {
+		return startWithContainer;
+	}
+
+	public void setStartWithContainer(Boolean startWithContainer) {
+		this.startWithContainer = startWithContainer;
+	}
+
+	public Boolean getStateful() {
+		return stateful;
+	}
 	
 }

+ 2 - 0
examcloud-task-service/src/main/java/cn/com/qmth/task/service/impl/ScheduleJobEntityServiceImpl.java

@@ -47,6 +47,8 @@ public class ScheduleJobEntityServiceImpl implements ScheduleJobEntityService{
 		scheduleJob.setJobGroup(scheduleJobEntity.getJobGroup());
 		scheduleJob.setSpringBean(scheduleJobEntity.getSpringBean());
 		scheduleJob.setCronExpression(scheduleJobEntity.getCronExpression());
+		Boolean startWithContainer = scheduleJobEntity.getStartWithContainer();
+		scheduleJob.setStartWithContainer(startWithContainer==null?false:startWithContainer);
 		return scheduleJob;
 	}
 

+ 4 - 12
examcloud-task-service/src/main/java/cn/com/qmth/task/service/job/JobsInitialization.java

@@ -7,7 +7,6 @@ import org.springframework.stereotype.Component;
 
 import cn.com.qmth.task.base.QuartzManager;
 import cn.com.qmth.task.base.ScheduleJob;
-import cn.com.qmth.task.base.enums.JobStatus;
 import cn.com.qmth.task.entity.ScheduleJobEntity;
 import cn.com.qmth.task.service.ScheduleJobEntityService;
 
@@ -24,17 +23,10 @@ public class JobsInitialization implements Runnable{
 	public void run() {
 		List<ScheduleJobEntity> scheduleJobEntitys = scheduleJobEntityService.findAll();
     	for(ScheduleJobEntity scheduleJobEntity:scheduleJobEntitys){
-    		try{
-    			ScheduleJob scheduleJob = scheduleJobEntityService.transformationToScheduleJob(scheduleJobEntity);
-        		quartzManager.addJob(scheduleJob);
-        		scheduleJobEntity.setJobStatus(JobStatus.RUNNING.name());
-    			scheduleJobEntity.setOperateResult(JobStatus.RUNNING.name()+" SUCCESS");
-    			scheduleJobEntityService.saveScheduleJobEntity(scheduleJobEntity);
-    		}catch(Exception e){
-    			
-    			scheduleJobEntity.setOperateResult(JobStatus.RUNNING.name()+" FAILED");
-    			scheduleJobEntityService.saveScheduleJobEntity(scheduleJobEntity);
-    		}
+			ScheduleJob scheduleJob = scheduleJobEntityService.transformationToScheduleJob(scheduleJobEntity);
+			if(scheduleJob.isStartWithContainer()){
+				quartzManager.addJob(scheduleJob);
+			}
     	}
 	} 
 	

+ 2 - 2
examcloud-task-service/src/main/java/cn/com/qmth/task/service/job/OeCleanExamRecordTask.java

@@ -41,11 +41,11 @@ public class OeCleanExamRecordTask extends AbstractTask{
 		ScheduleJobEntity scheduleJobEntity = scheduleJobEntityService.findByJobName(scheduleJob.getJobName());
 		try{
 			cleanExamRecordService.cleanExamExpiredExamRecord();
-			scheduleJobEntity.setOperateResult("execute success");
+			scheduleJobEntity.setOperateResult("EXECUTE SUCCESS");
 			scheduleJobEntity.setJobStatus(JobStatus.RUNNING.name());
 			scheduleJobEntityService.saveScheduleJobEntity(scheduleJobEntity);
 		}catch(Exception e){
-			scheduleJobEntity.setOperateResult("execute failed");
+			scheduleJobEntity.setOperateResult("EXECUTE FAILED");
 			scheduleJobEntityService.saveScheduleJobEntity(scheduleJobEntity);
 			e.printStackTrace();
 		}