Skip to content

Commit

Permalink
Merge pull request #108 from HathorNetwork/dev
Browse files Browse the repository at this point in the history
Release v0.1.14
  • Loading branch information
r4mmer authored Dec 14, 2021
2 parents 72d4d96 + dfc287e commit 9f6d82b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
21 changes: 20 additions & 1 deletion gateways/clients/hathor_core_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def __init__(self, domain: Optional[str] = None) -> None:
:type domain: str, optional
"""
self.domain = domain or HATHOR_CORE_DOMAIN
self.log = logger.new(client="async")

async def get(self, path: str, callback: Callable[[dict], None], params: Optional[dict] = None) -> None:
"""Make a get request async
Expand All @@ -46,8 +47,14 @@ async def get(self, path: str, callback: Callable[[dict], None], params: Optiona
try:
async with aiohttp.ClientSession() as session:
async with session.get(url, params=params) as response:
self.log.info(
"hathor_core_response",
path=path,
status=response.status,
body=await response.text())
callback(await response.json())
except Exception as e:
self.log.error("hathor_core_error", path=path, error=repr(e))
callback({'error': repr(e)})


Expand All @@ -59,6 +66,7 @@ class HathorCoreClient:
"""
def __init__(self, domain: Optional[str] = None) -> None:
self.domain = domain or HATHOR_CORE_DOMAIN
self.log = logger.new(client="sync")

def get(self, path: str, params: Optional[dict] = None, **kwargs: Any) -> Optional[dict]:
"""Make a get request
Expand All @@ -77,11 +85,22 @@ def get(self, path: str, params: Optional[dict] = None, **kwargs: Any) -> Option
try:
response = requests.get(url, params=params, **kwargs)
if response.status_code != 200:
logger.warning(f'Hathor Core Unexpected response ({response.status_code}): {response.text}')
self.log.warning(
"hathor_core_error",
path=path,
status=response.status_code,
body=response.text)
return None
self.log.info(
"hathor_core_response",
path=path,
status=response.status_code,
body=response.text)

return response.json()
except requests.ReadTimeout:
self.log.error("hathor_core_error", error="timeout", path=path)
raise HathorCoreTimeout('timeout')
except Exception as e:
self.log.error("hathor_core_error", error=repr(e), path=path)
return {'error': repr(e)}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hathor-explorer-service",
"version": "0.1.13",
"version": "0.1.14",
"description": "Hathor Explorer Service Serverless deps",
"dependencies": {
"serverless": "^2.44.0",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "hathor-explorer-service"
version = "0.1.13"
version = "0.1.14"
description = ""
authors = ["Hathor Labs <[email protected]>"]
license = "MIT"
Expand Down
7 changes: 7 additions & 0 deletions usecases/collect_nodes_statuses.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
from typing import Optional

from common.configuration import HATHOR_NODES
from common.logging import get_logger
from domain.network.node import Node
from gateways.clients.hathor_core_client import HathorCoreAsyncClient
from gateways.node_gateway import NodeGateway

logger = get_logger()


class CollectNodesStatuses:
""" Usecase class to collect nodes statuses
"""
def __init__(self, node_gateway: Optional[NodeGateway] = None) -> None:
self.node_gateway = node_gateway or NodeGateway()
self.log = logger.new()

async def collect(self) -> None:
"""Collect nodes statuses and send them to data aggregator
Expand All @@ -21,5 +25,8 @@ async def collect(self) -> None:
await node_gateway.get_node_status_async(self._send)

def _send(self, data: dict) -> None:
if 'error' in data:
self.log.warning("collect_status_error", error=data['error'])
return
node = Node.from_status_dict(data)
self.node_gateway.send_node_to_data_aggregator(node)

0 comments on commit 9f6d82b

Please sign in to comment.