fix: use DATETIME_FORMAT_MS_WITH_TZ instead of isoformat for last_data_timestamp
Addresses review feedback: prefer sientia_do's explicit datetime format constant over Python's isoformat()/fromisoformat() when round-tripping last_data_timestamp through Redis, matching the convention already used elsewhere in mongo_db.py and slot_manager.py.
This commit is contained in:
@@ -453,7 +453,7 @@ class MongoDB(SientiaMonitoring):
|
||||
- metadata (dict[str, Any]): Workflow execution metadata
|
||||
- collection_name (str): Name of the MongoDB collection
|
||||
- last_data_timestamp (str | None): Last processed timestamp
|
||||
(ISO-format string) for filtering
|
||||
(formatted per ``DATETIME_FORMAT_MS_WITH_TZ``) for filtering
|
||||
- base_data_filter (dict[str, Any]): Base query filter conditions
|
||||
|
||||
Returns:
|
||||
@@ -475,12 +475,15 @@ class MongoDB(SientiaMonitoring):
|
||||
else:
|
||||
# ``notification_queue.timestamp`` is stored as a native BSON
|
||||
# ``Date`` (``Notification.timestamp`` is a ``datetime``).
|
||||
# ``last_data_timestamp`` arrives here as an ISO-format string
|
||||
# (round-tripped through Redis), so it must be parsed back to
|
||||
# ``datetime`` for the ``$gt`` comparison to be type-correct.
|
||||
# ``last_data_timestamp`` arrives here as a string formatted per
|
||||
# ``DATETIME_FORMAT_MS_WITH_TZ`` (round-tripped through Redis),
|
||||
# so it must be parsed back to ``datetime`` for the ``$gt``
|
||||
# comparison to be type-correct.
|
||||
data_filter = {
|
||||
**base_data_filter,
|
||||
'timestamp': {'$gt': datetime.fromisoformat(last_data_timestamp)},
|
||||
'timestamp': {
|
||||
'$gt': datetime.strptime(last_data_timestamp, DATETIME_FORMAT_MS_WITH_TZ)
|
||||
},
|
||||
}
|
||||
|
||||
self.debug(f'Data filter: {data_filter}', metadata=metadata)
|
||||
|
||||
@@ -337,8 +337,9 @@ class SlotManager(SientiaMonitoring):
|
||||
|
||||
# ``timestamp`` is a native ``datetime``/``Timestamp`` (BSON Date from
|
||||
# Mongo), which the Redis repository's plain ``json.dumps`` cannot
|
||||
# serialize. Store it as an ISO-format string instead.
|
||||
last_data_timestamp = last_data_timestamp.isoformat()
|
||||
# serialize. Store it as a string formatted per
|
||||
# ``DATETIME_FORMAT_MS_WITH_TZ`` instead.
|
||||
last_data_timestamp = last_data_timestamp.strftime(DATETIME_FORMAT_MS_WITH_TZ)
|
||||
|
||||
try:
|
||||
self.redis_repository.set(key, last_data_timestamp, ttl=60 * 60 * 5)
|
||||
|
||||
Reference in New Issue
Block a user