Wait for connection to entityident

This commit is contained in:
Tobias Eidelpes 2021-06-13 22:59:06 +02:00
parent c36a3e1d85
commit 8b0a60d9ab
2 changed files with 26 additions and 18 deletions

View File

@ -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)

View File

@ -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'])