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 checkpoint for timestamps #154

Merged
merged 4 commits into from
Dec 2, 2024
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 @@ -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
Expand Down
19 changes: 10 additions & 9 deletions sekoia_automation/checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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


Expand Down
Loading