Skip to content

Commit

Permalink
Retry Pyxis requests on timeout
Browse files Browse the repository at this point in the history
The gql RequestsHTTPTransport has retries enabled, but it doesn't retry
when Pyxis requests timeout, for some requests, Pyxis may take more time
than its gateway timeout value to process them, and it will return the
result with error in response. In such cases, retrying may work.

This is a workaround for JIRA: CLOUDWF-9342
  • Loading branch information
qixiang committed Aug 8, 2023
1 parent 3b2be5a commit 437cf54
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions freshmaker/pyxis_gql.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from functools import cached_property
from typing import Optional

import backoff
import dogpile.cache
from gql import Client, gql
from gql.dsl import DSLQuery, DSLSchema, dsl_gql
Expand All @@ -45,6 +46,10 @@ def __init__(self, error: str | list[str], trace_id: Optional[str] = None):
super().__init__(msg)


class PyxisGQLRequestTimeout(PyxisGQLRequestError):
pass


class PyxisGQL:
region = dogpile.cache.make_region().configure(conf.dogpile_cache_backend)

Expand Down Expand Up @@ -73,6 +78,13 @@ def _get_graphql_schema(self):
self._client.execute(query)
return DSLSchema(self._client.schema)

@backoff.on_exception(
backoff.expo,
PyxisGQLRequestTimeout,
factor=30,
max_tries=3,
jitter=None, # use deterministic backoff, do not apply random jitter
)
def query(self, query_dsl):
"""Execute a GraphQL query with Domain Specific Language
Expand All @@ -85,6 +97,9 @@ def query(self, query_dsl):
error = response[response_field_name]["error"]
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:
raise PyxisGQLRequestTimeout(error=error, trace_id=trace_id)
raise PyxisGQLRequestError(error=error, trace_id=trace_id)

return response
Expand Down
1 change: 1 addition & 0 deletions yum-packages.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ git
httpd
mod_auth_gssapi
mod_ssl
python3-backoff
python3-defusedxml
python3-dogpile-cache
python3-fedmsg
Expand Down

0 comments on commit 437cf54

Please sign in to comment.