-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
31 lines (26 loc) · 926 Bytes
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import requests
class Server:
def __init__(self, endpoint, path="/healthcheck"):
self.endpoint = endpoint
self.path = path
self.healthy = True
self.timeout = 1
self.scheme = "http://"
self.open_connections = 0
def healthcheck_and_update_status(self):
try:
response = requests.get(
self.scheme + self.endpoint + self.path, timeout=self.timeout
)
if response.ok:
self.healthy = True
else:
self.healthy = False
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout):
self.healthy = False
def __eq__(self, other):
if isinstance(other, Server):
return self.endpoint == other.endpoint
return False
def __repr__(self):
return f"<Server: {self.endpoint} {self.healthy} {self.timeout}>"