Pārlūkot izejas kodu

优化定时调度事务

zhouhao 7 gadi atpakaļ
vecāks
revīzija
3e568db633

+ 3 - 1
hsweb-system/hsweb-system-schedule/hsweb-system-schedule-service/hsweb-system-schedule-service-simple/src/main/java/org/hswebframework/web/service/schedule/simple/DefaultScriptScheduleJobExecutor.java

@@ -8,6 +8,7 @@ import org.hswebframework.web.service.schedule.ScheduleJobExecutor;
 import org.hswebframework.web.service.schedule.ScheduleJobService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.Map;
 
@@ -25,6 +26,7 @@ public class DefaultScriptScheduleJobExecutor implements ScheduleJobExecutor {
     }
 
     @Override
+    @Transactional(rollbackFor = Throwable.class)
     public Object doExecuteJob(String jobId, Map<String, Object> parameter) {
         try {
             ScheduleJobEntity jobEntity = scheduleJobService.selectByPk(jobId);
@@ -35,7 +37,7 @@ public class DefaultScriptScheduleJobExecutor implements ScheduleJobExecutor {
 
             String jobMd5 = DigestUtils.md5Hex(jobEntity.getScript());
             //脚本发生变化,重新编译执行
-            if (engine.getContext(jobId)==null||!jobMd5.equals(engine.getContext(jobId).getMd5())) {
+            if (engine.getContext(jobId) == null || !jobMd5.equals(engine.getContext(jobId).getMd5())) {
                 engine.compile(jobId, jobEntity.getScript());
             }
             return engine.execute(jobId, parameter).getIfSuccess();