Просмотр исходного кода

fix:apiclient不支持跨进程

pudongliang 4 месяцев назад
Родитель
Сommit
64645d593f
1 измененных файлов с 33 добавлено и 19 удалено
  1. 33 19
      src/main/java/com/moka/gdtauto/service/impl/AdPlanConfServiceImpl.java

+ 33 - 19
src/main/java/com/moka/gdtauto/service/impl/AdPlanConfServiceImpl.java

@@ -638,14 +638,39 @@ public class AdPlanConfServiceImpl extends ServiceImpl<AdPlanConfMapper, AdPlanC
                     .collect(Collectors.toList());
                     .collect(Collectors.toList());
 
 
             // 使用虚拟线程并发处理创意资产,Semaphore限制最大并发数为100
             // 使用虚拟线程并发处理创意资产,Semaphore限制最大并发数为100
-            Semaphore semaphore = new Semaphore(20);
-            CountDownLatch latch = new CountDownLatch(allCreatives.size());
+            // TODO tencentAds不支持跨进程
+            //Semaphore semaphore = new Semaphore(20);
+            //CountDownLatch latch = new CountDownLatch(allCreatives.size());
             
             
-            try (ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor()) {
-                for (AdPlanCreative creative : allCreatives) {
-                    executor.submit(() -> {
-                        try {
-                            semaphore.acquire();
+            // try (ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor()) {
+            //     for (AdPlanCreative creative : allCreatives) {
+            //         executor.submit(() -> {
+            //             try {
+            //                 semaphore.acquire();
+            //                 prepareSingleCreativeAsset(tencentAds, accountId, creative);
+            //             } catch (Exception e) {
+            //                 log.error("准备创意资产失败, accountId={}, creativeId={}, creativeName={}", 
+            //                         accountId, creative.getId(), creative.getCreativeName(), e);
+            //                 adPlanCreativeService.lambdaUpdate()
+            //                     .eq(AdPlanCreative::getId, creative.getId())
+            //                     .set(AdPlanCreative::getFailReason, truncateError(e.getMessage()))
+            //                     .set(AdPlanCreative::getStatus, AdPlanStatus.FAILED)
+            //                     .update();
+            //             } finally {
+            //                 semaphore.release();
+            //                 latch.countDown();
+            //             }
+            //         });
+            //     }
+                
+            //     // 等待所有任务完成
+            //     latch.await();
+            // } catch (InterruptedException e) {
+            //     Thread.currentThread().interrupt();
+            //     log.error("等待创意资产准备完成被中断, accountId={}", accountId, e);
+            // }
+            for (AdPlanCreative creative : allCreatives) {
+                    try {
                             prepareSingleCreativeAsset(tencentAds, accountId, creative);
                             prepareSingleCreativeAsset(tencentAds, accountId, creative);
                         } catch (Exception e) {
                         } catch (Exception e) {
                             log.error("准备创意资产失败, accountId={}, creativeId={}, creativeName={}", 
                             log.error("准备创意资产失败, accountId={}, creativeId={}, creativeName={}", 
@@ -655,19 +680,8 @@ public class AdPlanConfServiceImpl extends ServiceImpl<AdPlanConfMapper, AdPlanC
                                 .set(AdPlanCreative::getFailReason, truncateError(e.getMessage()))
                                 .set(AdPlanCreative::getFailReason, truncateError(e.getMessage()))
                                 .set(AdPlanCreative::getStatus, AdPlanStatus.FAILED)
                                 .set(AdPlanCreative::getStatus, AdPlanStatus.FAILED)
                                 .update();
                                 .update();
-                        } finally {
-                            semaphore.release();
-                            latch.countDown();
-                        }
-                    });
+                        } 
                 }
                 }
-                
-                // 等待所有任务完成
-                latch.await();
-            } catch (InterruptedException e) {
-                Thread.currentThread().interrupt();
-                log.error("等待创意资产准备完成被中断, accountId={}", accountId, e);
-            }
         }
         }
 
 
         log.info("准备创意资产完成");
         log.info("准备创意资产完成");