Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix expiry timestamp #90

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading