aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/traccar/config/Keys.java9
-rw-r--r--src/main/java/org/traccar/database/NotificationManager.java11
2 files changed, 18 insertions, 2 deletions
diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java
index e7b07791f..3059c4f4b 100644
--- a/src/main/java/org/traccar/config/Keys.java
+++ b/src/main/java/org/traccar/config/Keys.java
@@ -1168,6 +1168,15 @@ public final class Keys {
List.of(KeyType.CONFIG));
/**
+ * If the event time is too old, we should not send notifications. This parameter is the threshold value in
+ * milliseconds. Default value is 15 minutes.
+ */
+ public static final ConfigKey<Long> NOTIFICATOR_TIME_THRESHOLD = new LongConfigKey(
+ "notificator.timeThreshold",
+ List.of(KeyType.CONFIG),
+ 15 * 60 * 1000L);
+
+ /**
* Traccar notification API key.
*/
public static final ConfigKey<String> NOTIFICATOR_TRACCAR_KEY = new StringConfigKey(
diff --git a/src/main/java/org/traccar/database/NotificationManager.java b/src/main/java/org/traccar/database/NotificationManager.java
index 3a57788fb..03cfba418 100644
--- a/src/main/java/org/traccar/database/NotificationManager.java
+++ b/src/main/java/org/traccar/database/NotificationManager.java
@@ -58,6 +58,7 @@ public class NotificationManager {
private final Geocoder geocoder;
private final boolean geocodeOnRequest;
+ private final long timeThreshold;
@Inject
public NotificationManager(
@@ -69,6 +70,7 @@ public class NotificationManager {
this.notificatorManager = notificatorManager;
this.geocoder = geocoder;
geocodeOnRequest = config.getBoolean(Keys.GEOCODER_ON_REQUEST);
+ timeThreshold = config.getLong(Keys.NOTIFICATOR_TIME_THRESHOLD);
}
private void updateEvent(Event event, Position position) {
@@ -78,6 +80,13 @@ public class NotificationManager {
LOGGER.warn("Event save error", error);
}
+ forwardEvent(event, position);
+
+ if (System.currentTimeMillis() - event.getEventTime().getTime() > timeThreshold) {
+ LOGGER.info("Skipping notifications for old event");
+ return;
+ }
+
var notifications = cacheManager.getDeviceObjects(event.getDeviceId(), Notification.class).stream()
.filter(notification -> notification.getType().equals(event.getType()))
.filter(notification -> {
@@ -115,8 +124,6 @@ public class NotificationManager {
});
});
}
-
- forwardEvent(event, position);
}
private void forwardEvent(Event event, Position position) {