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,6 +19,8 @@ Start all vehicles / traffic lights here
if __name__ == '__main__': if __name__ == '__main__':
ENTITY_IDENT_URL = 'http://entityident:5002/api/v1/resources/' ENTITY_IDENT_URL = 'http://entityident:5002/api/v1/resources/'
available = False
while not available:
try: try:
response = requests.get(ENTITY_IDENT_URL + 'cars') response = requests.get(ENTITY_IDENT_URL + 'cars')
cars = response.json() cars = response.json()
@ -27,15 +29,16 @@ if __name__ == '__main__':
traffic_lights = response.json() traffic_lights = response.json()
except requests.exceptions.ConnectionError as e: except requests.exceptions.ConnectionError as e:
print("Is the entity_ident_server running and reachable?") print("Is the entity_ident_server running and reachable?")
raise e continue
available = True
for traffic_light in traffic_lights['cursor']: for traffic_light in traffic_lights['cursor']:
print(traffic_light) print(traffic_light)
TrafficLight(tlid=traffic_light['id'], TrafficLight(tlid=traffic_light['id'],
switching_time=traffic_light['switchingTime']).start() switching_time=traffic_light['switchingTime']).start()
time.sleep(1) time.sleep(0.5)
for car in cars['cursor']: for car in cars['cursor']:
print(car) print(car)
Vehicle(vin=car['vin']).start_driving() 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/' ENTITY_IDENT_URL = 'http://entityident:5002/api/v1/resources/'
SCALING = 1
class Orchestrator: class Orchestrator:
# vehicle ids # vehicle ids
@ -38,6 +40,8 @@ class Orchestrator:
# re-use http session, is faster then request.ing everytime # re-use http session, is faster then request.ing everytime
self._session = requests.Session() self._session = requests.Session()
available = False
while not available:
try: try:
response = self._session.get(ENTITY_IDENT_URL + 'cars') response = self._session.get(ENTITY_IDENT_URL + 'cars')
cars = response.json() cars = response.json()
@ -46,7 +50,8 @@ class Orchestrator:
traffic_lights = response.json() traffic_lights = response.json()
except requests.exceptions.ConnectionError as e: except requests.exceptions.ConnectionError as e:
print("Is the entity_ident_server running and reachable?") print("Is the entity_ident_server running and reachable?")
raise e continue
available = True
for car in cars['cursor']: for car in cars['cursor']:
self.vins.append(car['vin']) self.vins.append(car['vin'])