diff options
author | Anton Tananaev <anton@traccar.org> | 2023-11-18 06:00:37 -0800 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2023-11-18 06:00:37 -0800 |
commit | a9ba9a58a868309a9fc83cdb8710159c7786ca32 (patch) | |
tree | c074fada48f5c65f532af0b355ab36d3937dd4da | |
parent | e5827b74db9432392b702f676fedb2aaacfd69f0 (diff) | |
download | trackermap-server-a9ba9a58a868309a9fc83cdb8710159c7786ca32.tar.gz trackermap-server-a9ba9a58a868309a9fc83cdb8710159c7786ca32.tar.bz2 trackermap-server-a9ba9a58a868309a9fc83cdb8710159c7786ca32.zip |
Skip old event notifications (fix #5217)
-rw-r--r-- | src/main/java/org/traccar/config/Keys.java | 9 | ||||
-rw-r--r-- | src/main/java/org/traccar/database/NotificationManager.java | 11 |
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) { |