瀏覽代碼

全量同步待发布内容

wangyunpeng 3 天之前
父節點
當前提交
05a99f65e6

+ 37 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/XxlJobService.java

@@ -183,6 +183,9 @@ public class XxlJobService {
     @Value("${preFilter.publish.content.thread.pool.size:4}")
     private Integer preFilterPublishContentThreadPoolSize;
 
+    @Value("${sync.publish.content.batch.job.size:20}")
+    private Integer syncPublishContentBatchJobSize;
+
     @XxlJob("checkPublishPlan")
     public ReturnT<String> checkPublishPlan(String param) {
         Long todayStart = DateUtils.getTodayStart();
@@ -1070,6 +1073,40 @@ public class XxlJobService {
         return ReturnT.SUCCESS;
     }
 
+    @XxlJob("syncGzhWaitingPublishContentBatch")
+    public ReturnT<String> syncGzhWaitingPublishContentBatch(String param) {
+        Long now = System.currentTimeMillis();
+        List<PublishPlan> planList = publishPlanRepository.getByChannelAndContentModalAndPlanTypeAndPlanStatus(ChannelEnum.wx.getVal(),
+                3, 1, 1);
+        List<String> planIds = planList.stream().map(PublishPlan::getId).collect(Collectors.toList());
+        List<PublishPlanAccountDTO> accountList = publishContentMapper.getPublishPlanAccounts(planIds);
+        Collections.shuffle(accountList);
+        CountDownLatch cdl = new CountDownLatch(accountList.size());
+        ExecutorService thread = new CommonThreadPoolExecutor(
+                syncPublishContentThreadPoolSize, syncPublishContentThreadPoolSize, 0L, TimeUnit.SECONDS,
+                new LinkedBlockingQueue<>(),
+                new ThreadFactoryBuilder().setNameFormat("syncGzhWaitingPublishContentBatch-%d").build(),
+                new ThreadPoolExecutor.AbortPolicy());
+        for (int i = 0; i < syncPublishContentBatchJobSize; i++) {
+            PublishPlanAccountDTO account = accountList.get(i);
+            thread.submit(() -> {
+                try {
+                    List<Content> contentList;
+                    contentList = aigcWaitingPublishContentService.getAllContent(account.getPlanId(), account.getAccountId(), null);
+                    savePublishContentCache(contentList, account.getPlanId(), account.getAccountId(), true, now);
+                } finally {
+                    cdl.countDown();
+                }
+            });
+        }
+        try {
+            cdl.await();
+        } catch (InterruptedException e) {
+            log.error("syncGzhWaitingPublishContentBatch error", e);
+        }
+        return ReturnT.SUCCESS;
+    }
+
     private void setPublishContentValue(PublishContentGzhWaiting item, Content content, String planId, String accountId,
                                         Long updateTimestamp) {
         item.setId(content.getId());

+ 5 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/web/XxlJobController.java

@@ -127,6 +127,11 @@ public class XxlJobController {
         service.syncGzhWaitingPublishContent(null);
     }
 
+    @GetMapping("/syncGzhWaitingPublishContentBatch")
+    public void syncGzhWaitingPublishContentBatch() {
+        service.syncGzhWaitingPublishContentBatch(null);
+    }
+
     @GetMapping("/gzhWaitingPublishContentPreFilter")
     public void gzhWaitingPublishContentPreFilter() {
         service.gzhWaitingPublishContentPreFilter();