From 8617e36e5b77d294147b3c77f52f64d00c83f93b Mon Sep 17 00:00:00 2001 From: lvoloshyn-sekoia Date: Fri, 29 Nov 2024 13:28:09 +0200 Subject: [PATCH 1/4] Fix checkpoint for timestamps --- CHANGELOG.md | 4 ++++ sekoia_automation/checkpoint.py | 19 ++++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 002493e..25d0a3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Fix checkpoint for timestamps + ## 1.18.0 - 2024-11-26 ### Changed diff --git a/sekoia_automation/checkpoint.py b/sekoia_automation/checkpoint.py index 7954e3e..e83e4b0 100644 --- a/sekoia_automation/checkpoint.py +++ b/sekoia_automation/checkpoint.py @@ -64,15 +64,15 @@ def datetime_to_file(self, dt: datetime) -> str: return dt.isoformat() @abstractmethod - def from_datetime(self, dt): + def from_datetime(self, dt: datetime) -> Any: raise NotImplementedError @abstractmethod - def to_datetime(self, rp): + def to_datetime(self, rp: Any) -> datetime: raise NotImplementedError @property - def offset(self) -> datetime: + def offset(self) -> Any: if self._most_recent_date_seen is None: if self._lock: self._lock.acquire() @@ -109,13 +109,14 @@ def offset(self) -> datetime: return self.from_datetime(self._most_recent_date_seen) @offset.setter - def offset(self, last_message_date: datetime) -> None: + def offset(self, last_message_date: datetime | int) -> None: if last_message_date is not None: # convert to inner representation - last_message_date = self.to_datetime(last_message_date) + last_message_datetime: datetime = self.to_datetime(last_message_date) + offset_to_compare: datetime = self.to_datetime(self.offset) - if self.offset is None or last_message_date > self.offset: - self._most_recent_date_seen = last_message_date + if self.offset is None or last_message_datetime > offset_to_compare: + self._most_recent_date_seen = last_message_datetime if self._lock: self._lock.acquire() @@ -139,10 +140,10 @@ def offset(self, last_message_date: datetime) -> None: class CheckpointDatetime(CheckpointDatetimeBase): - def from_datetime(self, dt): + def from_datetime(self, dt: datetime) -> datetime: return dt - def to_datetime(self, rp): + def to_datetime(self, rp: datetime) -> datetime: return rp From f1ac77ab22fd9058a0e810550c97eb283d105b7a Mon Sep 17 00:00:00 2001 From: lvoloshyn-sekoia Date: Fri, 29 Nov 2024 13:49:45 +0200 Subject: [PATCH 2/4] Fix checkpoint for timestamps --- sekoia_automation/checkpoint.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sekoia_automation/checkpoint.py b/sekoia_automation/checkpoint.py index e83e4b0..90db555 100644 --- a/sekoia_automation/checkpoint.py +++ b/sekoia_automation/checkpoint.py @@ -182,7 +182,7 @@ def from_datetime(self, dt) -> int: def to_datetime(self, rp: float | int) -> datetime: # timestamp -> inner representation - return datetime.fromtimestamp(rp / self.multiplier).astimezone(timezone.utc) + return datetime.fromtimestamp(rp / self.multiplier, tz=timezone.utc) class CheckpointCursor(Checkpoint): From ad04fd86a62793a5208d05fd38d221d9fbb1963e Mon Sep 17 00:00:00 2001 From: lvoloshyn-sekoia Date: Fri, 29 Nov 2024 13:58:18 +0200 Subject: [PATCH 3/4] Fix checkpoint for timestamps --- sekoia_automation/checkpoint.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sekoia_automation/checkpoint.py b/sekoia_automation/checkpoint.py index 90db555..49126ef 100644 --- a/sekoia_automation/checkpoint.py +++ b/sekoia_automation/checkpoint.py @@ -182,7 +182,7 @@ def from_datetime(self, dt) -> int: def to_datetime(self, rp: float | int) -> datetime: # timestamp -> inner representation - return datetime.fromtimestamp(rp / self.multiplier, tz=timezone.utc) + return datetime.fromtimestamp(rp / self.multiplier).replace(tzinfo=timezone.utc) class CheckpointCursor(Checkpoint): From 707f3fc369f057afdeb222e914925b42cbee86a9 Mon Sep 17 00:00:00 2001 From: lvoloshyn-sekoia Date: Fri, 29 Nov 2024 14:01:03 +0200 Subject: [PATCH 4/4] Fix checkpoint for timestamps --- sekoia_automation/checkpoint.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sekoia_automation/checkpoint.py b/sekoia_automation/checkpoint.py index 49126ef..e83e4b0 100644 --- a/sekoia_automation/checkpoint.py +++ b/sekoia_automation/checkpoint.py @@ -182,7 +182,7 @@ def from_datetime(self, dt) -> int: def to_datetime(self, rp: float | int) -> datetime: # timestamp -> inner representation - return datetime.fromtimestamp(rp / self.multiplier).replace(tzinfo=timezone.utc) + return datetime.fromtimestamp(rp / self.multiplier).astimezone(timezone.utc) class CheckpointCursor(Checkpoint):