瀏覽代碼

测试闭锁

syh 4 年之前
父節點
當前提交
d8c87caadd

+ 12 - 1
xxl-job-executor-samples/xxl-job-executor-sample-springboot/src/main/java/com/xxl/job/executor/jobhandler/BytedancePlanLoadJob.java

@@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import java.util.List;
+import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
@@ -19,12 +20,22 @@ public class BytedancePlanLoadJob {
     @Autowired
     private IByteDanceAdvertiserDataService advertiserDataService;
     static ExecutorService executorService = Executors.newFixedThreadPool(4);
+    static CountDownLatch countDownLatch = null;
 
     @XxlJob("bytedancePlanLoadJob")
     public void execute() throws Exception {
         //1:查询当日数据
         List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
-        tokens.forEach(token -> executorService.submit(() -> advertiserDataService.getAdvertiserPlan(token, "", null, null)));
+        countDownLatch = new CountDownLatch(tokens.size());
+        tokens.forEach(token -> executorService.submit(() -> {
+            try {
+                advertiserDataService.getAdvertiserPlan(token, "", null, null);
+            }catch (Exception e){
+            }finally {
+                countDownLatch.countDown();
+            }
+        }));
+        countDownLatch.await();
         XxlJobHelper.log("头条全量计划数据获取完成");
     }
 }

+ 3 - 1
xxl-job-executor-samples/xxl-job-executor-sample-springboot/src/main/java/com/xxl/job/executor/material/service/impl/ByteDanceAdvertiserDataServiceImpl.java

@@ -2,6 +2,7 @@ package com.xxl.job.executor.material.service.impl;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.xxl.job.core.context.XxlJobHelper;
 import com.xxl.job.executor.common.entity.CtopOauthToken;
 import com.xxl.job.executor.common.service.ICtopOauthTokenService;
 import com.xxl.job.executor.material.entity.*;
@@ -238,10 +239,11 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
 
     @Override
     public Map<String, Object> getAdvertiserPlan(CtopOauthToken token, String ids, String date, String updateDate) {
-        getAd(token, 1, ids, date, updateDate);
         Map<String, Object> resultMap = new HashMap<>();
+        getAd(token, 1, ids, date, updateDate);
         resultMap.put("code", 0);
         resultMap.put("message", "获取广告计划信息成功");
+        XxlJobHelper.log("头条计划数据获取完成:accountId=>{}",token.getAccountId());
         return resultMap;
     }