Harden network
This commit is contained in:
@@ -26,3 +26,5 @@ ORANGE_SPECIAL = SpecialEvent.points
|
|||||||
ORANGE_SPECIAL_BANK = ORANGE_SPECIAL_BANK_OPTIONS["BOTH"]
|
ORANGE_SPECIAL_BANK = ORANGE_SPECIAL_BANK_OPTIONS["BOTH"]
|
||||||
## Tech config
|
## Tech config
|
||||||
WAIT_TIME_TO_RESET_SECONDS = 0.6
|
WAIT_TIME_TO_RESET_SECONDS = 0.6
|
||||||
|
MAX_NETWORK_RETRIES = 10
|
||||||
|
NETWORK_SLEEP_TIME_SECONDS = 0.05
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
import requests_unixsocket as req
|
import requests_unixsocket as req
|
||||||
|
import config
|
||||||
|
from time import sleep
|
||||||
import socket
|
import socket
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
|
|
||||||
class Networking:
|
class Networking:
|
||||||
def __init__(self, output_server_address, input_socket_address):
|
def __init__(self, output_server_address, input_socket_address):
|
||||||
|
self.retries = 0
|
||||||
self.server_address = ""
|
self.server_address = ""
|
||||||
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()
|
||||||
@@ -16,7 +18,16 @@ class Networking:
|
|||||||
print("Connected to " + input_socket_address + " and started server " + self.server_address)
|
print("Connected to " + input_socket_address + " and started server " + self.server_address)
|
||||||
|
|
||||||
def get(self, path):
|
def get(self, path):
|
||||||
|
if self.retries < config.MAX_NETWORK_RETRIES:
|
||||||
|
logging.error("Network exception. Could not get " + path)
|
||||||
|
|
||||||
|
try:
|
||||||
response = self.output_session.get(self.server_address + path)
|
response = self.output_session.get(self.server_address + path)
|
||||||
|
except Exception:
|
||||||
|
self.retries += 1
|
||||||
|
sleep(config.NETWORK_SLEEP_TIME)
|
||||||
|
return self.get(path)
|
||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
return response.content
|
return response.content
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user