-
Notifications
You must be signed in to change notification settings - Fork 16
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
Unit test Ceph cache and fix timezone awareness #2723
Conversation
/hold |
eec4870
to
98034e8
Compare
/unhold |
/retest |
/assign @harshad16 |
- self.ceph.retrieve_document_attr(object_key=document_id, attr="LastModified").replace(tzinfo=timezone.utc) | ||
).total_seconds() | ||
|
||
if time_lived <= 14400.0: | ||
return time_lived | ||
return 14400.0 - time_lived | ||
|
||
return 0.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we return a timedelta object instead of a raw number of seconds ?
If not, I think we should at least use it internally to the function.
thoth/storages/ceph_cache.py
Outdated
@@ -46,11 +46,11 @@ def retrieve_document_ttl(self, document_id: str) -> float: | |||
|
|||
# Uses UTC time to be environment agnostic (no timezone) | |||
time_lived = ( | |||
datetime.now() | |||
datetime.now(timezone.utc) | |||
- self.ceph.retrieve_document_attr(object_key=document_id, attr="LastModified").replace(tzinfo=timezone.utc) | |||
).total_seconds() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
).total_seconds() | |
) |
thoth/storages/ceph_cache.py
Outdated
@@ -46,11 +46,11 @@ def retrieve_document_ttl(self, document_id: str) -> float: | |||
|
|||
# Uses UTC time to be environment agnostic (no timezone) | |||
time_lived = ( | |||
datetime.now() | |||
datetime.now(timezone.utc) | |||
- self.ceph.retrieve_document_attr(object_key=document_id, attr="LastModified").replace(tzinfo=timezone.utc) | |||
).total_seconds() | |||
|
|||
if time_lived <= 14400.0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if time_lived <= 14400.0: | |
if time_lived <= timedelta(hours=4): |
(this makes it clearer that 14400 seconds == 4 hours)
thoth/storages/ceph_cache.py
Outdated
- self.ceph.retrieve_document_attr(object_key=document_id, attr="LastModified").replace(tzinfo=timezone.utc) | ||
).total_seconds() | ||
|
||
if time_lived <= 14400.0: | ||
return time_lived | ||
return 14400.0 - time_lived |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return 14400.0 - time_lived | |
return timedelta(hours=4) - time_lived |
or if we don't want to return a timedelta
return 14400.0 - time_lived | |
return (timedelta(hours=4) - time_lived).total_seconds() |
- self.ceph.retrieve_document_attr(object_key=document_id, attr="LastModified").replace(tzinfo=timezone.utc) | ||
).total_seconds() | ||
|
||
if time_lived <= 14400.0: | ||
return time_lived | ||
return 14400.0 - time_lived | ||
|
||
return 0.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return 0.0 | |
return timedelta() |
Only if we switch to a timedelta return.
Btw, side comment: I'm not sure
|
/lgtm
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: VannTen The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Related Issues and Dependencies
Fixes #2722
Related to #2666
This introduces a breaking change
This should yield a new module release