Skip to content

Commit

Permalink
Merge pull request #41 from stakewise/fix-timeout
Browse files Browse the repository at this point in the history
Fix oracle timeout
  • Loading branch information
tsudmi authored Dec 27, 2021
2 parents f85d5f5 + 90bcfeb commit fc570d1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
28 changes: 17 additions & 11 deletions oracle/oracle/clients.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from typing import Any, Dict, List, Union

import backoff
Expand All @@ -24,31 +25,36 @@
aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
)

# set default timeout to 5 minutes
DEFAULT_TIMEOUT = 5 * 60
gql_logger = logging.getLogger("gql_logger")
gql_handler = logging.StreamHandler()
gql_logger.addHandler(gql_handler)
gql_logger.setLevel(logging.ERROR)

# set default GQL query execution timeout to 30 seconds
EXECUTE_TIMEOUT = 30

@backoff.on_exception(backoff.expo, Exception, max_time=300)

@backoff.on_exception(backoff.expo, Exception, max_time=300, logger=gql_logger)
async def execute_sw_gql_query(query: DocumentNode, variables: Dict) -> Dict:
"""Executes GraphQL query."""
transport = AIOHTTPTransport(url=STAKEWISE_SUBGRAPH_URL, timeout=DEFAULT_TIMEOUT)
async with Client(transport=transport) as session:
transport = AIOHTTPTransport(url=STAKEWISE_SUBGRAPH_URL)
async with Client(transport=transport, execute_timeout=EXECUTE_TIMEOUT) as session:
return await session.execute(query, variable_values=variables)


@backoff.on_exception(backoff.expo, Exception, max_time=300)
@backoff.on_exception(backoff.expo, Exception, max_time=300, logger=gql_logger)
async def execute_uniswap_v3_gql_query(query: DocumentNode, variables: Dict) -> Dict:
"""Executes GraphQL query."""
transport = AIOHTTPTransport(url=UNISWAP_V3_SUBGRAPH_URL, timeout=DEFAULT_TIMEOUT)
async with Client(transport=transport) as session:
transport = AIOHTTPTransport(url=UNISWAP_V3_SUBGRAPH_URL)
async with Client(transport=transport, execute_timeout=EXECUTE_TIMEOUT) as session:
return await session.execute(query, variable_values=variables)


@backoff.on_exception(backoff.expo, Exception, max_time=300)
@backoff.on_exception(backoff.expo, Exception, max_time=300, logger=gql_logger)
async def execute_ethereum_gql_query(query: DocumentNode, variables: Dict) -> Dict:
"""Executes GraphQL query."""
transport = AIOHTTPTransport(url=ETHEREUM_SUBGRAPH_URL, timeout=DEFAULT_TIMEOUT)
async with Client(transport=transport) as session:
transport = AIOHTTPTransport(url=ETHEREUM_SUBGRAPH_URL)
async with Client(transport=transport, execute_timeout=EXECUTE_TIMEOUT) as session:
return await session.execute(query, variable_values=variables)


Expand Down
2 changes: 2 additions & 0 deletions oracle/oracle/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@ async def main() -> None:
)

# check stakewise graphql connection
logger.info("Checking connection to graph node...")
await get_finalized_block()

# aiohttp session
session = aiohttp.ClientSession()

# check ETH2 API connection
logger.info("Checking connection to ETH2 node...")
await get_finality_checkpoints(session)

# check whether oracle is part of the oracles set
Expand Down

0 comments on commit fc570d1

Please sign in to comment.