Skip to content

Commit

Permalink
fix: stop DRY (#325)
Browse files Browse the repository at this point in the history
no need for 2 handlers, decrease complexity

the only difference is an emitted event that is not listened too anywhere
  • Loading branch information
JarbasAl authored Jan 9, 2025
1 parent 4d86161 commit 61c3ed4
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions ovos_workshop/skills/ovos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,7 @@ def _register_system_event_handlers(self):
"""
Register default messagebus event handlers
"""
self.add_event('mycroft.stop', self._handle_stop, speak_errors=False)
self.add_event('mycroft.stop', self._handle_session_stop, speak_errors=False)
self.add_event(f"{self.skill_id}.stop", self._handle_session_stop, speak_errors=False)
self.add_event(f"{self.skill_id}.stop.ping", self._handle_stop_ack, speak_errors=False)

Expand Down Expand Up @@ -1356,22 +1356,6 @@ def _handle_session_stop(self, message: Message):
self.__responses[sess.session_id] = None # abort any ongoing get_response
self.bus.emit(message.reply(f"{self.skill_id}.stop.response", data))

def _handle_stop(self, message):
"""Handler for the "mycroft.stop" signal. Runs the user defined
`stop()` method.
"""
message.context['skill_id'] = self.skill_id
self.bus.emit(message.forward(self.skill_id + ".stop"))
sess = SessionManager.get(message)
try:
stopped = self.stop_session(sess) or self.stop() or False
LOG.debug(f"{self.skill_id} stopped: {stopped}")
if stopped:
self.bus.emit(message.reply("mycroft.stop.handled",
{"by": "skill:" + self.skill_id}))
except Exception as e:
self.log.exception(f'Failed to stop skill: {self.skill_id}: {e}')

def default_shutdown(self):
"""
Parent function called internally to shut down everything.
Expand Down

0 comments on commit 61c3ed4

Please sign in to comment.