Skip to content

Commit

Permalink
Merge pull request #720 from populationgenomics/backoff_retrier_for_r…
Browse files Browse the repository at this point in the history
…equests

Adds backoff retry to query and query_async
  • Loading branch information
MattWellie authored Apr 3, 2024
2 parents e098d13 + a36667d commit 0a30f4e
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 6.8.0
current_version = 6.9.0
commit = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>[A-z0-9-]+)
Expand Down
2 changes: 1 addition & 1 deletion api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from db.python.utils import get_logger

# This tag is automatically updated by bump2version
_VERSION = '6.8.0'
_VERSION = '6.9.0'

logger = get_logger()

Expand Down
2 changes: 1 addition & 1 deletion deploy/python/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.8.0
6.9.0
27 changes: 25 additions & 2 deletions metamist/graphql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@
- construct queries using the `gql` function (which validates graphql syntax)
- validate queries with metamist schema (by fetching the schema)
"""

import os
from json.decoder import JSONDecodeError
from typing import Any, Dict

import backoff
from gql import Client
from gql import gql as gql_constructor
from gql.transport.aiohttp import AIOHTTPTransport
from gql.transport.aiohttp import log as aiohttp_logger
from gql.transport.exceptions import TransportServerError
from gql.transport.requests import RequestsHTTPTransport
from gql.transport.requests import log as requests_logger

# this does not import itself, it imports the module
from graphql import DocumentNode # type: ignore
from requests.exceptions import HTTPError

from cpg_utils.cloud import get_google_identity_token

Expand Down Expand Up @@ -137,8 +142,17 @@ def validate(doc: DocumentNode, client=None, use_local_schema=False):


# use older style typing to broaden supported Python versions
@backoff.on_exception(
backoff.expo,
exception=(HTTPError, JSONDecodeError, TransportServerError),
max_time=10,
max_tries=3,
)
def query(
_query: str | DocumentNode, variables: Dict = None, client: Client = None, log_response: bool = False
_query: str | DocumentNode,
variables: Dict | None = None,
client: Client | None = None,
log_response: bool = False,
) -> Dict[str, Any]:
"""Query the metamist GraphQL API"""
if variables is None:
Expand All @@ -159,8 +173,17 @@ def query(
return response


@backoff.on_exception(
backoff.expo,
exception=(HTTPError, JSONDecodeError, TransportServerError),
max_time=10,
max_tries=3,
)
async def query_async(
_query: str | DocumentNode, variables: Dict = None, client: Client = None, log_response: bool = False
_query: str | DocumentNode,
variables: Dict | None = None,
client: Client | None = None,
log_response: bool = False,
) -> Dict[str, Any]:
"""Asynchronously query the Metamist GraphQL API"""
if variables is None:
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
setup(
name=PKG,
# This tag is automatically updated by bump2version
version='6.8.0',
version='6.9.0',
description='Python API for interacting with the Sample API system',
long_description=readme,
long_description_content_type='text/markdown',
url='https://github.com/populationgenomics/metamist',
license='MIT',
packages=all_packages,
install_requires=[
'backoff>=2.2.1',
'click',
'google-auth',
'google-api-core', # dependency to google-auth that however is not
Expand Down
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "metamist",
"version": "6.8.0",
"version": "6.9.0",
"private": true,
"dependencies": {
"@apollo/client": "^3.7.3",
Expand Down

0 comments on commit 0a30f4e

Please sign in to comment.