Bläddra i källkod

Fix Senslog fetcher config - startAt corresponding to the connector schedule

Lukas Cerny 10 månader sedan
förälder
incheckning
7e2deacdd0

+ 1 - 1
config/senslog1Analytics.yaml

@@ -29,5 +29,5 @@ connectors:
         fetcher: "Senslog"
         pusher: "Analytics"
         period: 600 # 10 minutes
-        startAt: "08:00:00"
+        startAt: "13:00:00"
 #        initDelay: 5

+ 22 - 8
connector-fetch-senslog-v1/src/main/java/cz/senslog/connector/fetch/senslog/v1/SenslogConfig.java

@@ -12,7 +12,11 @@ import java.net.URISyntaxException;
 import java.time.Instant;
 import java.time.LocalDateTime;
 import java.time.ZoneOffset;
+import java.time.temporal.ChronoUnit;
 import java.util.TimeZone;
+import java.util.function.Supplier;
+
+import static java.time.ZoneId.systemDefault;
 
 public class SenslogConfig {
 
@@ -36,7 +40,8 @@ public class SenslogConfig {
     }
 
     private final TimeZone timeZone;
-    private final LocalDateTime startDate;
+    private LocalDateTime startDate;
+    private final Supplier<LocalDateTime> startDateSupplier;
     private final String user;
     private final Integer interval;
     private final AllowedStation allowedStation;
@@ -49,19 +54,25 @@ public class SenslogConfig {
         this.timeZone = TimeZone.getTimeZone(defaultConfig.getStringProperty("timeZone"));
         String startDate = defaultConfig.getStringProperty("startDate");
 
+        boolean isDelay = defaultConfig.containsProperty("delayStartDate");
         LocalDateTime tempStartDate = null;
         if (startDate.equalsIgnoreCase("now")) {
-            tempStartDate = LocalDateTime.ofInstant(Instant.now(), timeZone.toZoneId());
+            if (isDelay) {
+                int delay = defaultConfig.getIntegerProperty("delayStartDate");
+                startDateSupplier = () -> LocalDateTime.ofInstant(Instant.now(), timeZone.toZoneId()).minusMinutes(delay);
+            } else {
+                startDateSupplier = () -> LocalDateTime.ofInstant(Instant.now(), timeZone.toZoneId());
+            }
         } else {
             LocalDateTime configSystemTime = defaultConfig.getLocalDateTimeProperty("startDate");
-            tempStartDate = LocalDateTime.ofInstant(configSystemTime.atZone(ZoneOffset.systemDefault()).toInstant(), timeZone.toZoneId());
-        }
-
-        if (defaultConfig.containsProperty("delayStartDate")) {
-            tempStartDate = tempStartDate.minusMinutes(defaultConfig.getIntegerProperty("delayStartDate"));
+            if (isDelay) {
+                int delay = defaultConfig.getIntegerProperty("delayStartDate");
+                startDateSupplier = () -> LocalDateTime.ofInstant(configSystemTime.atZone(systemDefault()).toInstant(), timeZone.toZoneId()).minusMinutes(delay);
+            } else {
+                startDateSupplier = () -> LocalDateTime.ofInstant(configSystemTime.atZone(systemDefault()).toInstant(), timeZone.toZoneId());
+            }
         }
 
-        this.startDate = tempStartDate;
         this.user = defaultConfig.getStringProperty("user");
         this.interval = defaultConfig.getIntegerProperty("interval");
         this.allowedStation = new AllowedStation(defaultConfig.getPropertyConfig("allowedStation"));
@@ -78,6 +89,9 @@ public class SenslogConfig {
     }
 
     public LocalDateTime getStartDate() {
+        if (startDate == null) {
+            startDate = startDateSupplier.get();
+        }
         return startDate;
     }