Selaa lähdekoodia

Merge branch 'wyp/0918-xxlJob' of Server/long-article-recommend into master

wangyunpeng 10 kuukautta sitten
vanhempi
commit
91216887ce

+ 5 - 0
long-article-recommend-service/pom.xml

@@ -126,6 +126,11 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-webflux</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>com.xuxueli</groupId>
+            <artifactId>xxl-job-core</artifactId>
+        </dependency>
     </dependencies>
 
 

+ 56 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/config/XxlJobConfig.java

@@ -0,0 +1,56 @@
+package com.tzld.longarticle.recommend.server.config;
+
+import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * @author ehlxr
+ * @since 2022-01-17 13:48.
+ */
+@Configuration
+public class XxlJobConfig {
+    private final Logger log = LoggerFactory.getLogger(this.getClass());
+    @Value("${xxl.job.admin.addresses}")
+    private String adminAddresses;
+
+    @Value("${xxl.job.accessToken}")
+    private String accessToken;
+
+    @Value("${xxl.job.executor.appname}")
+    private String appName;
+
+    @Value("${xxl.job.executor.address}")
+    private String address;
+
+    @Value("${xxl.job.executor.ip}")
+    private String ip;
+
+    @Value("${xxl.job.executor.port}")
+    private int port;
+
+    @Value("${xxl.job.executor.logpath}")
+    private String logPath;
+
+    @Value("${xxl.job.executor.logretentiondays}")
+    private int logRetentionDays;
+
+    @Bean
+    public XxlJobSpringExecutor xxlJobExecutor() {
+        log.info("xxl-job config init");
+        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
+        xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
+        xxlJobSpringExecutor.setAppname(appName);
+        xxlJobSpringExecutor.setAddress(address);
+        xxlJobSpringExecutor.setIp(ip);
+        xxlJobSpringExecutor.setPort(port);
+        xxlJobSpringExecutor.setAccessToken(accessToken);
+        xxlJobSpringExecutor.setLogPath(logPath);
+        xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
+        return xxlJobSpringExecutor;
+    }
+
+}

+ 5 - 3
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/DataDashboardService.java

@@ -26,13 +26,14 @@ import com.tzld.longarticle.recommend.server.repository.mapper.longArticle.LongA
 import com.tzld.longarticle.recommend.server.util.DateUtils;
 import com.tzld.longarticle.recommend.server.util.MapBuilder;
 import com.tzld.longarticle.recommend.server.util.feishu.FeiShu;
+import com.xxl.job.core.biz.model.ReturnT;
+import com.xxl.job.core.handler.annotation.XxlJob;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.util.Pair;
 import org.springframework.http.*;
-import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 import org.springframework.web.client.RestTemplate;
 
@@ -78,10 +79,11 @@ public class DataDashboardService {
         exportFeishuNewSortStrategy(dateStrList, sheetToken, "7d4e12");
     }
 
-    @Scheduled(cron = "0 0 4 * * ?")
-    public void scheduledExport() {
+    @XxlJob("scheduledExport")
+    public ReturnT<String> scheduledExport(String param) {
         List<String> dateStrList = DateUtils.getBeforeDays(null, 5);
         exportFeishuNewSortStrategy(dateStrList, sheetToken, "7d4e12");
+        return ReturnT.SUCCESS;
     }
 
 

+ 5 - 0
long-article-recommend-service/src/main/resources/application-dev.yml

@@ -85,6 +85,11 @@ spring:
 apollo:
   meta: http://devapolloconfig-internal.piaoquantv.com
 
+xxl:
+  job:
+    admin:
+      addresses: http://xxl-job-test-internal.piaoquantv.com/xxl-job-admin
+
 aliyun:
   log:
     endpoint: cn-hangzhou.log.aliyuncs.com

+ 5 - 0
long-article-recommend-service/src/main/resources/application-prod.yml

@@ -68,6 +68,11 @@ spring:
 apollo:
   meta: http://apolloconfig-internal.piaoquantv.com
 
+xxl:
+  job:
+    admin:
+      addresses: http://xxl-job-internal.piaoquantv.com/xxl-job-admin
+
 aliyun:
   log:
     endpoint: cn-hangzhou-intranet.log.aliyuncs.com

+ 13 - 1
long-article-recommend-service/src/main/resources/application.yml

@@ -54,4 +54,16 @@ apollo:
   cacheDir: /datalog/apollo-cache-dir
 
 mybatis:
-  mapper-locations: classpath:/mapper/*.xml
+  mapper-locations: classpath:/mapper/*.xml
+
+
+xxl:
+  job:
+    accessToken:
+    executor:
+      address:
+      appname: longarticle-recommend-server
+      ip:
+      logpath: /datalog/xxl-job/
+      logretentiondays: 30
+      port: 9999