Skip to content

Commit

Permalink
api: increase timeout and adding the possibility to disable log
Browse files Browse the repository at this point in the history
Changelog-Added: api: increase req timeout and adding the possibility to disable log

Signed-off-by: Vincenzo Palazzo <[email protected]>
  • Loading branch information
vincenzopalazzo committed Apr 24, 2022
1 parent 20e6c1f commit c63b467
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions lnmetrics_api/lnmetrics_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
author: https://github.com/vincenzopalazzo
"""
import logging

from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport
from gql.transport.requests import log as requests_logger
from .queries import GET_NODE, GET_NODES, GET_METRIC_ONE


Expand All @@ -14,9 +17,16 @@ class LNMetricsClient:
LNMetrics Client implementation
"""

def __init__(self, service_url: str) -> None:
def __init__(
self, service_url: str, timeout: int = 40, log_level=logging.WARNING
) -> None:
transport = AIOHTTPTransport(url=service_url)
self.client = Client(transport=transport, fetch_schema_from_transport=True)
requests_logger.setLevel(log_level)
self.client = Client(
transport=transport,
fetch_schema_from_transport=True,
execute_timeout=timeout,
)

def call(self, query, variables: dict = None) -> dict:
"""Generic method to make a query to the Graphql Server"""
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["Vincenzo Palazzo <[email protected]>"]

[tool.poetry.dependencies]
python = "^3.7"
gql = "^3.1.0"
gql = "^3.2.0"
aiohttp = "^3.8.1"

[tool.poetry.dev-dependencies]
Expand Down

0 comments on commit c63b467

Please sign in to comment.