Skip to content

Commit

Permalink
Fix checkpoint for timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
lvoloshyn-sekoia committed Nov 29, 2024
1 parent d0c1479 commit 8617e36
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
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

0 comments on commit 8617e36

Please sign in to comment.