moved node info to base checker, removed port from base checker

This commit is contained in:
kiriharu 2021-01-04 02:27:07 +03:00
parent 2b4ce947bd
commit ec55ad216e
2 changed files with 12 additions and 12 deletions

View File

@ -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

View File

@ -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
)