Skip to content

Commit

Permalink
Fix expiry timestamp
Browse files Browse the repository at this point in the history
Co-authored-by: Antonio Gisondi <antonio.gisondi@secomind.com>
Signed-off-by: Luca Arato <luca.arato@secomind.com>
  • Loading branch information
lucaato and harlem88 committed Aug 20, 2024
1 parent 5b2f878 commit 804a25e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Fix failed message expiration check.

## [1.1.0] - 2023-01-16

## [1.1.0-alpha.0] - 2022-12-15
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.PrimaryKey;
import java.util.concurrent.TimeUnit;
import org.astarteplatform.devicesdk.transport.AstarteFailedMessage;

@Entity(tableName = "failed_messages")
Expand All @@ -30,7 +31,7 @@ public AstarteAndroidFailedMessage(String topic, byte[] payload, int qos) {
}

public AstarteAndroidFailedMessage(String topic, byte[] payload, int qos, int relativeExpiry) {
this.absoluteExpiry = System.currentTimeMillis() + relativeExpiry;
this.absoluteExpiry = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(relativeExpiry);
this.topic = topic;
this.payload = payload;
this.qos = qos;
Expand Down Expand Up @@ -61,7 +62,11 @@ public void setAbsoluteExpiry(long absoluteExpiry) {

@Override
public boolean isExpired() {
return absoluteExpiry > System.currentTimeMillis();
if (absoluteExpiry <= 0) {
return false;
}

return absoluteExpiry < System.currentTimeMillis();
}

public long getStorageId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.j256.ormlite.field.DataType;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
import java.util.concurrent.TimeUnit;
import org.astarteplatform.devicesdk.transport.AstarteFailedMessage;

@DatabaseTable(tableName = "failed_messages")
Expand Down Expand Up @@ -34,7 +35,7 @@ public AstarteGenericFailedMessage(String topic, byte[] payload, int qos) {
}

public AstarteGenericFailedMessage(String topic, byte[] payload, int qos, int relativeExpiry) {
this.absoluteExpiry = System.currentTimeMillis() + relativeExpiry;
this.absoluteExpiry = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(relativeExpiry);
this.topic = topic;
this.payload = payload;
this.qos = qos;
Expand All @@ -57,7 +58,11 @@ public int getQos() {

@Override
public boolean isExpired() {
return absoluteExpiry > System.currentTimeMillis();
if (absoluteExpiry <= 0) {
return false;
}

return absoluteExpiry < System.currentTimeMillis();
}

public long getStorageId() {
Expand Down

0 comments on commit 804a25e

Please sign in to comment.