From 2b5fe9f652ec976939084178cf72b1cdba2ce180 Mon Sep 17 00:00:00 2001 From: Wilfred Tyler Gee Date: Tue, 8 May 2018 09:04:36 -0700 Subject: [PATCH 1/2] Check safety during transition If the state doesn't successfully change, check the safety between each iteration and if False send to parking Note: no test for this written --- pocs/state/machine.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pocs/state/machine.py b/pocs/state/machine.py index 46533ffc7..300f49808 100644 --- a/pocs/state/machine.py +++ b/pocs/state/machine.py @@ -137,7 +137,9 @@ def run(self, exit_when_done=False, run_once=False): # If we didn't successfully transition, sleep a while then try again if not state_changed: - if _loop_iteration > 5: + if self.is_safe() is False: + self.next_state = 'parking' + elif _loop_iteration > 5: self.logger.warning("Stuck in current state for 5 iterations, parking") self.next_state = 'parking' else: From e658bc6dd962a034ed95ada4ac30fa34ea4b5289 Mon Sep 17 00:00:00 2001 From: Wilfred Tyler Gee Date: Sun, 27 May 2018 09:03:36 +1000 Subject: [PATCH 2/2] Addig log message for failed state transitions --- pocs/state/machine.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pocs/state/machine.py b/pocs/state/machine.py index 300f49808..4966ccc43 100644 --- a/pocs/state/machine.py +++ b/pocs/state/machine.py @@ -137,13 +137,20 @@ def run(self, exit_when_done=False, run_once=False): # If we didn't successfully transition, sleep a while then try again if not state_changed: + self.logger.warning("Failed to transition from {} to {}", + self.state, self.next_state) if self.is_safe() is False: + self.logger.warning( + "Conditions have become unsafe; setting next state to 'parking'") self.next_state = 'parking' elif _loop_iteration > 5: self.logger.warning("Stuck in current state for 5 iterations, parking") self.next_state = 'parking' else: _loop_iteration = _loop_iteration + 1 + self.logger.warning( + "Sleeping for a bit, then trying the transition again (loop: {})", + _loop_iteration) self.sleep(with_status=False) else: _loop_iteration = 0