diff --git a/components/i_feed/i_feed.py b/components/i_feed/i_feed.py index d60deb8..04b1d11 100644 --- a/components/i_feed/i_feed.py +++ b/components/i_feed/i_feed.py @@ -19,23 +19,26 @@ Start all vehicles / traffic lights here if __name__ == '__main__': ENTITY_IDENT_URL = 'http://entityident:5002/api/v1/resources/' - try: - response = requests.get(ENTITY_IDENT_URL + 'cars') - cars = response.json() + available = False + while not available: + try: + response = requests.get(ENTITY_IDENT_URL + 'cars') + cars = response.json() - response = requests.get(ENTITY_IDENT_URL + 'traffic_lights') - traffic_lights = response.json() - except requests.exceptions.ConnectionError as e: - print("Is the entity_ident_server running and reachable?") - raise e + response = requests.get(ENTITY_IDENT_URL + 'traffic_lights') + traffic_lights = response.json() + except requests.exceptions.ConnectionError as e: + print("Is the entity_ident_server running and reachable?") + continue + available = True for traffic_light in traffic_lights['cursor']: print(traffic_light) TrafficLight(tlid=traffic_light['id'], switching_time=traffic_light['switchingTime']).start() - time.sleep(1) + time.sleep(0.5) for car in cars['cursor']: print(car) Vehicle(vin=car['vin']).start_driving() - time.sleep(10) + time.sleep(15) diff --git a/components/orchestration/orchestrator.py b/components/orchestration/orchestrator.py index cfd64b7..1937438 100644 --- a/components/orchestration/orchestrator.py +++ b/components/orchestration/orchestrator.py @@ -21,6 +21,8 @@ sys.modules['target_velocity'] = target_velocity ENTITY_IDENT_URL = 'http://entityident:5002/api/v1/resources/' +SCALING = 1 + class Orchestrator: # vehicle ids @@ -38,15 +40,18 @@ class Orchestrator: # re-use http session, is faster then request.ing everytime self._session = requests.Session() - try: - response = self._session.get(ENTITY_IDENT_URL + 'cars') - cars = response.json() + available = False + while not available: + try: + response = self._session.get(ENTITY_IDENT_URL + 'cars') + cars = response.json() - response = self._session.get(ENTITY_IDENT_URL + 'traffic_lights') - traffic_lights = response.json() - except requests.exceptions.ConnectionError as e: - print("Is the entity_ident_server running and reachable?") - raise e + response = self._session.get(ENTITY_IDENT_URL + 'traffic_lights') + traffic_lights = response.json() + except requests.exceptions.ConnectionError as e: + print("Is the entity_ident_server running and reachable?") + continue + available = True for car in cars['cursor']: self.vins.append(car['vin'])