harden network
This commit is contained in:
@@ -9,13 +9,19 @@ class Networking:
|
|||||||
def __init__(self, output_server_address, input_socket_address):
|
def __init__(self, output_server_address, input_socket_address):
|
||||||
self.retries = 0
|
self.retries = 0
|
||||||
self.server_address = ""
|
self.server_address = ""
|
||||||
|
self.output_server_address = output_server_address
|
||||||
|
self.input_socket_address = input_socket_address
|
||||||
|
self.__connect__(output_server_address, input_socket_address)
|
||||||
|
|
||||||
|
|
||||||
|
def __connect__(self):
|
||||||
self.input_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
self.input_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||||
self.output_session = req.Session()
|
self.output_session = req.Session()
|
||||||
adapter = req.adapters.UnixAdapter(pool_connections=1)
|
adapter = req.adapters.UnixAdapter(pool_connections=1)
|
||||||
self.output_session.mount('http+unix://', adapter)
|
self.output_session.mount('http+unix://', adapter)
|
||||||
self.server_address = "http+unix://" + output_server_address.replace("/", "%2F")
|
self.server_address = "http+unix://" + self.output_server_address.replace("/", "%2F")
|
||||||
self.input_socket.connect(input_socket_address)
|
self.input_socket.connect(self.input_socket_address)
|
||||||
print("Connected to " + input_socket_address + " and started server " + self.server_address)
|
print("Connected to " + self.input_socket_address + " and started server " + self.server_address)
|
||||||
|
|
||||||
def get(self, path):
|
def get(self, path):
|
||||||
if self.retries > config.MAX_NETWORK_RETRIES:
|
if self.retries > config.MAX_NETWORK_RETRIES:
|
||||||
@@ -24,10 +30,11 @@ class Networking:
|
|||||||
try:
|
try:
|
||||||
response = self.output_session.get(self.server_address + path)
|
response = self.output_session.get(self.server_address + path)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error("Network exception. Could not get " + path)
|
logging.error("Network exception. Could not get " + path + ".... Reconnecting!")
|
||||||
logging.error(e)
|
logging.error(e)
|
||||||
self.retries += 1
|
self.retries += 1
|
||||||
sleep(config.NETWORK_SLEEP_TIME_SECONDS)
|
sleep(config.NETWORK_SLEEP_TIME_SECONDS)
|
||||||
|
self.__connect__()
|
||||||
return self.get(path)
|
return self.get(path)
|
||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|||||||
Reference in New Issue
Block a user