fallback start, end, failure messages (#1108)
==== Tech Notes ==== Add mycroft.skill.handler.start and mycroft.skill.handler.complete to fallback handler. handler in data field will be called "fallback" upon completion the used handler will be reported in the "fallback_handler" data entry. * fix * pep8 * fallback handler namepull/1099/merge
parent
838e2dd7d8
commit
f5806b86c5
|
@ -37,7 +37,6 @@ from mycroft.util.log import LOG
|
|||
|
||||
__author__ = 'seanfitz'
|
||||
|
||||
|
||||
MainModule = '__init__'
|
||||
|
||||
|
||||
|
@ -142,7 +141,8 @@ def load_skill(skill_descriptor, emitter, skill_id, BLACKLISTED_SKILLS=None):
|
|||
skill_descriptor["name"]))
|
||||
except:
|
||||
LOG.error(
|
||||
"Failed to load skill: " + skill_descriptor["name"], exc_info=True)
|
||||
"Failed to load skill: " + skill_descriptor["name"],
|
||||
exc_info=True)
|
||||
return None
|
||||
|
||||
|
||||
|
@ -162,8 +162,7 @@ def get_handler_name(handler):
|
|||
Returns: handler name as string
|
||||
"""
|
||||
name = ''
|
||||
if '__self__' in dir(handler) and \
|
||||
'name' in dir(handler.__self__):
|
||||
if '__self__' in dir(handler) and 'name' in dir(handler.__self__):
|
||||
name += handler.__self__.name + '.'
|
||||
name += handler.__name__
|
||||
return name
|
||||
|
@ -190,12 +189,15 @@ def intent_handler(intent_parser):
|
|||
|
||||
def intent_file_handler(intent_file):
|
||||
""" Decorator for adding a method as an intent file handler. """
|
||||
|
||||
def real_decorator(func):
|
||||
@wraps(func)
|
||||
def handler_method(*args, **kwargs):
|
||||
return func(*args, **kwargs)
|
||||
|
||||
_intent_file_list.append((intent_file, func))
|
||||
return handler_method
|
||||
|
||||
return real_decorator
|
||||
|
||||
|
||||
|
@ -332,6 +334,7 @@ class MycroftSkill(object):
|
|||
intent handler the function will need the self
|
||||
variable passed as well.
|
||||
"""
|
||||
|
||||
def wrapper(message):
|
||||
try:
|
||||
# Indicate that the skill handler is starting
|
||||
|
@ -369,6 +372,7 @@ class MycroftSkill(object):
|
|||
# Indicate that the skill handler has completed
|
||||
self.emitter.emit(Message('mycroft.skill.handler.complete',
|
||||
data={'handler': name}))
|
||||
|
||||
if handler:
|
||||
self.emitter.on(name, wrapper)
|
||||
self.events.append((name, wrapper))
|
||||
|
@ -672,15 +676,29 @@ class FallbackSkill(MycroftSkill):
|
|||
"""Goes through all fallback handlers until one returns True"""
|
||||
|
||||
def handler(message):
|
||||
# indicate fallback handling start
|
||||
ws.emit(Message("mycroft.skill.handler.start",
|
||||
data={'handler': "fallback"}))
|
||||
for _, handler in sorted(cls.fallback_handlers.items(),
|
||||
key=operator.itemgetter(0)):
|
||||
try:
|
||||
if handler(message):
|
||||
# indicate completion
|
||||
ws.emit(Message(
|
||||
'mycroft.skill.handler.complete',
|
||||
data={'handler': "fallback",
|
||||
"fallback_handler": get_handler_name(
|
||||
handler)}))
|
||||
return
|
||||
except Exception as e:
|
||||
LOG.info('Exception in fallback: ' + str(e))
|
||||
ws.emit(Message('complete_intent_failure'))
|
||||
LOG.warning('No fallback could handle intent.')
|
||||
# indicate completion with exception
|
||||
ws.emit(Message('mycroft.skill.handler.complete',
|
||||
data={'handler': "fallback",
|
||||
'exception':
|
||||
"No fallback could handle intent."}))
|
||||
|
||||
return handler
|
||||
|
||||
|
|
Loading…
Reference in New Issue