fix circuitbreaker exception

This commit is contained in:
Marco Zeisler 2021-05-27 20:31:33 +02:00
parent 8e5580ca7b
commit 4c87baf225
2 changed files with 18 additions and 16 deletions

View File

@ -9,6 +9,7 @@ from circuitbreaker import circuit
from dse_shared_libs.traffic_light_color import TrafficLightColor from dse_shared_libs.traffic_light_color import TrafficLightColor
from dse_shared_libs.message_broker_wrapper import MBWrapper from dse_shared_libs.message_broker_wrapper import MBWrapper
from dse_shared_libs.traffic_light_state import TrafficLightState from dse_shared_libs.traffic_light_state import TrafficLightState
from pika.exceptions import AMQPConnectionError
SWITCHING_TIME = 500 SWITCHING_TIME = 500
# Scale speed of switching by factor x # Scale speed of switching by factor x
@ -65,7 +66,7 @@ class TrafficLight:
def stop(self): def stop(self):
self.running = False self.running = False
@circuit(failure_threshold=10, expected_exception=ConnectionError) @circuit(failure_threshold=10, expected_exception=AMQPConnectionError)
def send_status_update(self): def send_status_update(self):
print(self.tlid, self.current_color, self.last_switch) print(self.tlid, self.current_color, self.last_switch)
self._tl_mb.send(pickle.dumps( self._tl_mb.send(pickle.dumps(
@ -78,10 +79,10 @@ if __name__ == '__main__':
tl1 = TrafficLight(tlid='traffic-light-1', switching_time=SWITCHING_TIME) tl1 = TrafficLight(tlid='traffic-light-1', switching_time=SWITCHING_TIME)
tl1.start() tl1.start()
# time.sleep(1) time.sleep(1)
# tl2 = TrafficLight(tlid='traffic-light-2', switching_time=240) tl2 = TrafficLight(tlid='traffic-light-2', switching_time=240)
# tl2.start() tl2.start()
#
# time.sleep(1) time.sleep(1)
# tl3 = TrafficLight(tlid='traffic-light-3', switching_time=360) tl3 = TrafficLight(tlid='traffic-light-3', switching_time=360)
# tl3.start() tl3.start()

View File

@ -13,6 +13,7 @@ from dse_shared_libs.message_broker_wrapper import MBWrapper
# Lat, Long # Lat, Long
from dse_shared_libs.target_velocity import TargetVelocity from dse_shared_libs.target_velocity import TargetVelocity
from pika.exceptions import AMQPConnectionError
STARTING_POINT = geopy.Point(48.853, 2.349) STARTING_POINT = geopy.Point(48.853, 2.349)
# in km/h # in km/h
@ -202,7 +203,7 @@ class Vehicle:
self.last_update = datetime.now() self.last_update = datetime.now()
self.nce = False self.nce = False
@circuit(failure_threshold=10, expected_exception=ConnectionError) @circuit(failure_threshold=10, expected_exception=AMQPConnectionError)
def send_status_update(self): def send_status_update(self):
print(self.driven_kms, '\t', self.daf) print(self.driven_kms, '\t', self.daf)
self._daf_mb.send(pickle.dumps(self.daf)) self._daf_mb.send(pickle.dumps(self.daf))
@ -220,10 +221,10 @@ if __name__ == "__main__":
v1 = Vehicle(vin='SB164ABN1PE082000') v1 = Vehicle(vin='SB164ABN1PE082000')
v1.start_driving() v1.start_driving()
# time.sleep(1) time.sleep(1)
# v2 = Vehicle(vin='SB999ABN1PE082111') v2 = Vehicle(vin='SB999ABN1PE082111')
# v2.start_driving() v2.start_driving()
#
# time.sleep(0.5) time.sleep(0.5)
# v3 = Vehicle(vin='SB555ABN1PE082555') v3 = Vehicle(vin='SB555ABN1PE082555')
# v3.start_driving() v3.start_driving()