Browse Source

测试定时任务同时执行

dsx 2 years ago
parent
commit
310bf216e2
1 changed files with 37 additions and 33 deletions
  1. 37 33
      src/main/java/com/fdkankan/scene/schedule/ScheduleJob.java

+ 37 - 33
src/main/java/com/fdkankan/scene/schedule/ScheduleJob.java

@@ -11,6 +11,8 @@ import lombok.extern.log4j.Log4j2;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
@@ -19,6 +21,7 @@ import javax.annotation.PostConstruct;
 @RefreshScope
 @Log4j2
 @Component
+@EnableAsync
 public class ScheduleJob {
 
     @Value("${environment:#{null}}")
@@ -85,8 +88,9 @@ public class ScheduleJob {
      * 删除已删除场景原始资源及caches
      * 每天凌晨执行
      */
-    @PostConstruct
-    @Scheduled(cron="0 0 1 * * ?")
+//    @PostConstruct
+    @Async
+    @Scheduled(cron="0/5 * * * * ?")
     public void cleanOss4DeletedSceneV3() {
         log.info("删除已删除V3场景原始资源开始");
         try {
@@ -94,16 +98,16 @@ public class ScheduleJob {
         } catch (InterruptedException e) {
             e.printStackTrace();
         }
-        String lockKey = RedisLockKey.LOCK_CLEAN_SCENE_DELETED_ORIG_V3;
-        try {
-            boolean lock = redisLockUtil.lock(lockKey, 24*60*60);
-            if(!lock){
-                return;
-            }
-            sceneCleanOrigService.cleanOss4DeletedSceneV3();
-        }finally {
-            redisLockUtil.unlockLua(lockKey);
-        }
+//        String lockKey = RedisLockKey.LOCK_CLEAN_SCENE_DELETED_ORIG_V3;
+//        try {
+//            boolean lock = redisLockUtil.lock(lockKey, 24*60*60);
+//            if(!lock){
+//                return;
+//            }
+//            sceneCleanOrigService.cleanOss4DeletedSceneV3();
+//        }finally {
+//            redisLockUtil.unlockLua(lockKey);
+//        }
         log.info("删除已删除V3场景原始资源结束");
     }
 
@@ -112,27 +116,27 @@ public class ScheduleJob {
      * 删除已删除场景原始资源及caches
      * 每天凌晨执行
      */
-    @PostConstruct
-    @Scheduled(cron="0 0 1 * * ?")
-    public void cleanOss4DeletedSceneV4() {
-        log.info("删除已删除V4场景原始资源开始");
-        try {
-            Thread.sleep(60000L);
-        } catch (InterruptedException e) {
-            e.printStackTrace();
-        }
-        String lockKey = RedisLockKey.LOCK_CLEAN_SCENE_DELETED_ORIG_V4;
-        try {
-            boolean lock = redisLockUtil.lock(lockKey, 24*60*60);
-            if(!lock){
-                return;
-            }
-            sceneCleanOrigService.cleanOss4DeletedSceneV4();
-        }finally {
-            redisLockUtil.unlockLua(lockKey);
-        }
-        log.info("删除已删除V4场景原始资源结束");
-    }
+//    @PostConstruct
+//    @Scheduled(cron="0 0 1 * * ?")
+//    public void cleanOss4DeletedSceneV4() {
+//        log.info("删除已删除V4场景原始资源开始");
+//        try {
+//            Thread.sleep(60000L);
+//        } catch (InterruptedException e) {
+//            e.printStackTrace();
+//        }
+//        String lockKey = RedisLockKey.LOCK_CLEAN_SCENE_DELETED_ORIG_V4;
+//        try {
+//            boolean lock = redisLockUtil.lock(lockKey, 24*60*60);
+//            if(!lock){
+//                return;
+//            }
+//            sceneCleanOrigService.cleanOss4DeletedSceneV4();
+//        }finally {
+//            redisLockUtil.unlockLua(lockKey);
+//        }
+//        log.info("删除已删除V4场景原始资源结束");
+//    }
 
 //    /**
 //     * 删除测试相机场景原始资源及caches