瀏覽代碼

refactor: 优化采集定时上报,采用时间间隔策略,间隔时间默认是1s

zhanghaijun 3 年之前
父節點
當前提交
ea77c3725a

+ 2 - 10
src/assembly/assembly.xml

@@ -36,21 +36,13 @@
             <lineEnding>unix</lineEnding>
             <filtered>true</filtered>
         </fileSet>
-        <fileSet>
-            <directory>src/main/resources</directory>
-            <outputDirectory>config</outputDirectory>
-            <fileMode>0755</fileMode>
-            <filtered>true</filtered>
-            <includes>
-                <include>*.yaml</include>
-                <include>*.properties</include>
-            </includes>
-        </fileSet>
         <fileSet>
             <directory>${project.build.directory}/classes</directory>
             <outputDirectory>/conf</outputDirectory>
             <includes>
                 <include>application.*</include>
+                <include>*.yml</include>
+                <include>*.properties</include>
             </includes>
         </fileSet>
         <fileSet>

+ 0 - 2
src/main/java/com/cec/plugins/config/properties/ProjectProperties.java

@@ -32,8 +32,6 @@ public class ProjectProperties {
         private int retries = 3;
         /** 间隔时间(毫秒) */
         private long delayMillis = 1000L;
-        /** 采集数据上报 */
-        private String collectCron = "0/1 * * * * ?";
 
         public String getHttpUtl(String url) {
             return this.getUrl() + url;

+ 4 - 4
src/main/java/com/cec/plugins/service/task/TaskCollectService.java

@@ -13,7 +13,7 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
-import org.springframework.scheduling.support.CronTrigger;
+import org.springframework.scheduling.support.PeriodicTrigger;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
@@ -45,12 +45,12 @@ public class TaskCollectService {
 
     public void startReported(DtoPolicy policyDto) {
         stopReported();
-        String cron = properties.getPlatform().getCollectCron();
+        long delayMillis = properties.getPlatform().getDelayMillis();
         future = threadPoolTaskScheduler.schedule(() -> {
             log.info("###### 执行上报采集数据 ######");
             reportPolicy(policyDto);
-        }, triggerContext -> new CronTrigger(cron).nextExecutionTime(triggerContext));
-        log.info("###### 开始上报采集数据定时,cron: {} ######", cron);
+        }, triggerContext -> new PeriodicTrigger(delayMillis).nextExecutionTime(triggerContext));
+        log.info("###### 开始上报采集数据定时,delayMillis: {} ######", delayMillis);
     }
 
     public void stopReported() {

+ 0 - 1
src/main/resources/application-prod.yml

@@ -33,7 +33,6 @@ project:
     url: http://192.168.30.252:8080
     retries: 3
     delay-millis: 1000
-    collect-cron: 0/1 * * * * ?
   plugin:
     ip-address: 172.16.20.1
     port: ${server.port}

+ 0 - 1
src/main/resources/application.yml

@@ -33,7 +33,6 @@ project:
     url: ${PLATFORM_URL:http://127.0.0.1:${server.port}}
     retries: ${PLATFORM_RETRIES:3}
     delay-millis: ${PLATFORM_DELAY-MILLIS:1000}
-    collect-cron: 0/1 * * * * ?
   plugin:
     ip-address: ${PLUGIN_HOST:127.0.0.1}
     port: ${PLUGIN_PORT:${server.port}}