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

Updates the SearchIdentifier updateTime #755

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
9 changes: 7 additions & 2 deletions ezidapp/management/commands/proc-link-checker-update.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import impl.log
from impl.open_search_doc import OpenSearchDoc
import opensearchpy.exceptions
import time

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -98,9 +99,13 @@ def run(self):
)
si2.linkIsBroken = newValue
si2.computeHasIssues()
si2.save(update_fields=["linkIsBroken", "hasIssues"])

si2.updateTime = int(time.time())
si2.save(update_fields=["updateTime", "linkIsBroken", "hasIssues"])
open_s = OpenSearchDoc(identifier=si2)
open_s.update_link_issues(link_is_broken=si2.linkIsBroken, has_issues=si2.hasIssues)
open_s.update_link_issues(link_is_broken=si2.linkIsBroken,
has_issues=si2.hasIssues,
update_time=si2.updateTime)
except ezidapp.models.identifier.SearchIdentifier.DoesNotExist:
log.exception('SearchIdentifier.DoesNotExist')
except opensearchpy.exceptions.OpenSearchException as e:
Expand Down
6 changes: 4 additions & 2 deletions impl/open_search_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from opensearchpy.exceptions import NotFoundError
from django.conf import settings
import urllib
import time

# the functools allows memoizing the results of functions, so they're not recalculated every time (ie cached
# results if called more than once on the same instance)
Expand Down Expand Up @@ -138,10 +139,11 @@ def remove_from_index(self):
return True
return False

def update_link_issues(self, link_is_broken=False, has_issues=False):
# Note that this time is passed in as an integer, but it's converted to an iso datetime for opensearch
def update_link_issues(self, link_is_broken=False, has_issues=False, update_time=int(time.time())):
dict_to_update = {
'open_search_updated': datetime.datetime.now().isoformat(),
'update_time': datetime.datetime.now().isoformat(),
'update_time': datetime.datetime.utcfromtimestamp(update_time).isoformat(),
'link_is_broken': link_is_broken,
'has_issues': has_issues }

Expand Down
5 changes: 3 additions & 2 deletions tests/test_open_search_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def test_update_link_issues(mock_client, open_search_doc):
mock_client.update.return_value = mock_response

# Act
result = open_search_doc.update_link_issues(link_is_broken=True, has_issues=True)
result = open_search_doc.update_link_issues(link_is_broken=True, has_issues=True, update_time=1727984570)

# Assert
mock_client.update.assert_called_once_with(
Expand All @@ -282,7 +282,8 @@ def test_update_link_issues(mock_client, open_search_doc):
'open_search_updated': ANY, # Use unittest.mock.ANY if the exact value doesn't matter
'update_time': ANY,
'link_is_broken': True,
'has_issues': True
'has_issues': True,
'update_time': '2024-10-03T19:42:50'
}}
)
assert result is True
Expand Down