Skip to content

Commit

Permalink
fix(components): correctly go through shutdown sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
domire8 committed Oct 9, 2024
1 parent 1b8d582 commit 5f113e2
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions source/modulo_components/modulo_components/lifecycle_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,25 +226,40 @@ def on_shutdown(self, previous_state: LifecycleState) -> TransitionCallbackRetur
TRANSITION_CALLBACK_SUCCESS transitions to 'Finalized'
TRANSITION_CALLBACK_FAILURE, TRANSITION_CALLBACK_ERROR or any uncaught exceptions to 'ErrorProcessing'
"""
def error_processing(self):
self.get_logger().error("Entering into the error processing transition state.")
return TransitionCallbackReturn.ERROR

self.get_logger().debug(f"on_shutdown called from previous state {previous_state.label}.")
if not self._has_error:
if previous_state.state_id == State.PRIMARY_STATE_FINALIZED:
return TransitionCallbackReturn.SUCCESS
if previous_state.state_id == State.PRIMARY_STATE_ACTIVE:
if not self.__handle_deactivate():
self.get_logger().debug("Shutdown failed during intermediate deactivation!")
return error_processing(self)
if not self.__handle_cleanup():
self.get_logger().debug("Shutdown failed during intermediate cleanup!")
return error_processing(self)
if not self.__handle_shutdown():
return error_processing(self)
self._finalize_interfaces()
return TransitionCallbackReturn.SUCCESS
if previous_state.state_id == State.PRIMARY_STATE_INACTIVE:
if not self.__handle_cleanup():
self.get_logger().debug("Shutdown failed during intermediate cleanup!")
return error_processing(self)
if not self.__handle_shutdown():
return error_processing(self)
self._finalize_interfaces()
return TransitionCallbackReturn.SUCCESS
if previous_state.state_id == State.PRIMARY_STATE_UNCONFIGURED:
if not self.__handle_shutdown():
self.get_logger().error("Entering into the error processing transition state.")
return TransitionCallbackReturn.ERROR
return error_processing(self)
self._finalize_interfaces()
return TransitionCallbackReturn.SUCCESS
self.get_logger().warn(f"Invalid transition 'shutdown' from state {previous_state.label}.")
self.get_logger().error("Entering into the error processing transition state.")
return TransitionCallbackReturn.ERROR
return error_processing(self)

def __handle_shutdown(self) -> bool:
"""
Expand Down

0 comments on commit 5f113e2

Please sign in to comment.