From ec55ad216ec8d12b31a9227477a862cef013870a Mon Sep 17 00:00:00 2001 From: kiriharu Date: Mon, 4 Jan 2021 02:27:07 +0300 Subject: [PATCH] moved node info to base checker, removed port from base checker --- apps/api/api/checkers/base.py | 9 ++++++--- apps/api/api/checkers/http.py | 15 ++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/apps/api/api/checkers/base.py b/apps/api/api/checkers/base.py index 488e5eb..46d680f 100644 --- a/apps/api/api/checkers/base.py +++ b/apps/api/api/checkers/base.py @@ -1,12 +1,15 @@ -from core.coretypes import Response +from core.coretypes import Response, APINodeInfo +from api.config import NODE_NAME, NODE_LOCATION from abc import ABC class BaseChecker(ABC): - def __init__(self, target: str, port: int): + def __init__(self, target: str): self.target = target - self.port = port + self.node_info = APINodeInfo( + name=NODE_NAME, location=NODE_LOCATION + ) def check(self) -> Response: raise NotImplementedError diff --git a/apps/api/api/checkers/http.py b/apps/api/api/checkers/http.py index a6547e2..cbb9d48 100644 --- a/apps/api/api/checkers/http.py +++ b/apps/api/api/checkers/http.py @@ -1,6 +1,6 @@ from core.coretypes import ( Response, HttpCheckerResponse, APINodeInfo, - ResponseStatus, HttpErrorCodes, ErrorPayload, + ResponseStatus, ErrorCodes, ErrorPayload, ) from requests import Session from requests.exceptions import ConnectionError @@ -16,7 +16,8 @@ class HttpChecker(BaseChecker): default_schema_re = re.compile("^[hH][tT][tT][pP].*") def __init__(self, target: str, port: int): - super(HttpChecker, self).__init__(target, port) + super(HttpChecker, self).__init__(target) + self.port = port self.session = Session() def check(self) -> Response: @@ -36,11 +37,9 @@ class HttpChecker(BaseChecker): status=ResponseStatus.ERROR, payload=ErrorPayload( message="Failed to establish a new connection", - code=HttpErrorCodes.ConnectError, + code=ErrorCodes.ConnectError, ), - node=APINodeInfo( - name=NODE_NAME, location=NODE_LOCATION - ) + node=self.node_info ) end_time = time.time() @@ -51,7 +50,5 @@ class HttpChecker(BaseChecker): time=end_time - start_time, status_code=request.status_code ), - node=APINodeInfo( - name=NODE_NAME, location=NODE_LOCATION - ) + node=self.node_info )