Skip to content

Commit

Permalink
Fix retry for Pyxis request timeout
Browse files Browse the repository at this point in the history
In 31cc4ca, we added retry mechanism when Pyxis request timeout, however
we detect the Pyxis request timeout by:

    if "Pyxis API was unable to fetch data from MongoDB in time" in error

`error` is actually a dict, not a string, so this doesn't work.

JIRA: CWFHEALTH-2315
  • Loading branch information
qixiang committed Sep 13, 2023
1 parent ce9f124 commit fb89e02
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 4 additions & 1 deletion freshmaker/pyxis_gql.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ def query(self, query_dsl):
if error is not None:
trace_id = self._client.transport.response_headers.get("trace_id", False)

if "Pyxis API was unable to fetch data from MongoDB in time" in error:
if (
error["detail"]
and "Pyxis API was unable to fetch data from MongoDB in time" in error["detail"]
):
raise PyxisGQLRequestTimeout(error=error, trace_id=trace_id)
raise PyxisGQLRequestError(error=error, trace_id=trace_id)

Expand Down
3 changes: 1 addition & 2 deletions tests/test_pyxis_gql.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ def test_log_trace_id(mock_client, mock_transport):
result = {
"find_images": {
"data": [],
"error": ["something went wrong"],
"error": {"status": 500, "detail": "something went wrong"},
"page": 0,
"page_size": 250,
"total": 2,
Expand All @@ -574,6 +574,5 @@ def test_log_trace_id(mock_client, mock_transport):
content_sets=["rhel-8-for-x86_64-baseos-rpms"],
)
except PyxisGQLRequestError as e:
print(e)
assert e.error == str(result["find_images"]["error"])
assert e.trace_id == mock_transport.return_value.response_headers["trace_id"]

0 comments on commit fb89e02

Please sign in to comment.