diff --git a/config/sample-development.engine.ini b/config/sample-development.engine.ini index 7cdbdd4313ce3f5d795a546ec048ac43dbf9825e..2213b3864c082a2474a8855ec8fdf419127198c1 100644 --- a/config/sample-development.engine.ini +++ b/config/sample-development.engine.ini @@ -65,6 +65,10 @@ api_engine_store_clock="http://localhost:8008/api/v1/clock" # Engine API endpoint to store health information api_engine_store_health="http://localhost:8008/api/v1/source/health/${ENGINE_NUMBER}" +## ENGINE-CORE ## +# Host and port of the local engine backchannel (Network Socket for e.g. sending track service updates) +api_engine_control_host="localhost:1337" + [scheduler] # Database settings: Use 'postgresql', 'sqlite' or 'mysql'. In case of SQLite the "db_name" is the name of the file. db_type="postgresql" diff --git a/config/sample-docker.engine.ini b/config/sample-docker.engine.ini index 734dcfaede2c25b2915a3fff53c853ff5d0b940a..5290ebd7bf1b4d21b3cebab9e176c457cc408ffc 100644 --- a/config/sample-docker.engine.ini +++ b/config/sample-docker.engine.ini @@ -65,6 +65,10 @@ api_engine_store_clock="http://127.0.0.1:8008/api/v1/clock" # Engine API endpoint to store health information api_engine_store_health="http://127.0.0.1:8008/api/v1/source/health/${ENGINE_NUMBER}" +## ENGINE-CORE ## +# Host and port of the local engine backchannel (Network Socket for e.g. sending track service updates) +api_engine_control_host="0.0.0.0:1337" + [scheduler] # Database settings: Use 'postgresql', 'sqlite' or 'mysql'. In case of SQLite the "db_name" is the name of the file. db_type="postgresql" diff --git a/config/sample-production.engine.ini b/config/sample-production.engine.ini index 36bbd9a10f487de54f4beef7edc57d12d7faed0a..87e6dfce7e9d76bc0a73dac649d651e1425a49b8 100644 --- a/config/sample-production.engine.ini +++ b/config/sample-production.engine.ini @@ -65,6 +65,10 @@ api_engine_store_clock="http://localhost:8008/api/v1/clock" # Engine API endpoint to store health information api_engine_store_health="http://localhost:8008/api/v1/source/health/${ENGINE_NUMBER}" +## ENGINE-CORE ## +# Host and port of the local engine backchannel (Network Socket for e.g. sending track service updates) +api_engine_control_host="localhost:1337" + [scheduler] # Database settings: Use 'postgresql', 'sqlite' or 'mysql'. In case of SQLite the "db_name" is the name of the file. db_type="postgresql" diff --git a/src/control.py b/src/control.py index b88f542709e8a35c4c71de03f6bf7566bd1ea2e4..3fdfd6470ac120fff1128a26fa90e75d91b673d4 100644 --- a/src/control.py +++ b/src/control.py @@ -74,7 +74,6 @@ class SocketControlInterface: service is primarily utilized to store new playlogs. """ - PORT = 1337 ACTION_ON_METADATA = "on_metadata" instance = None @@ -98,8 +97,10 @@ class SocketControlInterface: self.config = AuraConfig.config() self.logger = logging.getLogger("AuraEngine") self.event_dispatcher = event_dispatcher - host = "127.0.0.1" - thread = Thread(target=self.run, args=(self.logger, host)) + url_parts = self.config.get("api_engine_control_host").split(":") + host = url_parts[0] + port = int(url_parts[1]) + thread = Thread(target=self.run, args=(self.logger, host, port)) thread.start() @staticmethod @@ -111,14 +112,14 @@ class SocketControlInterface: SocketControlInterface.instance = SocketControlInterface(event_dispatcher) return SocketControlInterface.instance - def run(self, logger, host): + def run(self, logger, host, port): """ Starts the socket server """ while True: try: self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self.server.bind((host, SocketControlInterface.PORT)) + self.server.bind((host, port)) break except OSError: wait_time = 2 @@ -126,9 +127,7 @@ class SocketControlInterface: self.logger.error(SU.red(msg)) time.sleep(wait_time) - logger.info( - SU.yellow(f"[ECI] Listening at {host}:{SocketControlInterface.PORT}") - ) + logger.info(SU.yellow(f"[ECI] Listening at {host}:{port}")) self.server.listen() while True: diff --git a/src/scheduling/api.py b/src/scheduling/api.py index fe1abcdfa12e1c0bcd23c886ee830e0214906cda..98af6d5f451aeb35db465d3796fd0606b83ba9a0 100644 --- a/src/scheduling/api.py +++ b/src/scheduling/api.py @@ -158,30 +158,37 @@ class ApiFetcher(threading.Thread): Returns: ([Timeslot]): An array of timeslots """ + response = None timeslots = None headers = {"content-type": "application/json"} + url = self.steering_calendar_url + self.logger.debug("Fetch timeslots from Steering API...") try: - self.logger.debug("Fetch timeslots from Steering API...") - response = requests.get( - self.steering_calendar_url, data=None, headers=headers - ) - if not response.status_code == 200: - self.logger.critical( - SU.red( - "HTTP Status: %s | Timeslots could not be fetched! Response: %s" - % (str(response.status_code), response.text) - ) - ) - return None - timeslots = response.json() + response = requests.get(url, data=None, headers=headers) + except requests.exceptions.ConnectionError: + msg = SU.red(f"Bad Request | requesting Steering timeslots at {url}") + self.logger.error(msg) + except requests.exceptions.Timeout: + msg = SU.red(f"Timeout | Requesting Steering timeslots at {url}") + self.logger.error(msg) except Exception as e: - self.logger.critical( - SU.red("Error while requesting timeslots from Steering!"), e - ) + msg = f"Unknown Error | Requesting Steering timeslots at {url}" + self.logger.error(SU.red(msg, e)) + finally: + if not response: + return None + + if not response.status_code == 200: + code = str(response.status_code) + text = response.text + msg = f"HTTP Status: {code} | Timeslots could not be fetched! Response: {text}" + self.logger.error(SU.red(msg)) + return None + timeslots = response.json() if not timeslots: - self.logger.error(SU.red("Got no timeslots via Playout API (Steering)!")) + self.logger.error(SU.red(f"Got no timeslots via {url} (Steering)!")) return None return self.polish_timeslots(timeslots)