Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improved skill settings #1151

Merged
merged 5 commits into from
Oct 13, 2017
Merged

improved skill settings #1151

merged 5 commits into from
Oct 13, 2017

Conversation

LearnedVector
Copy link
Contributor

@LearnedVector LearnedVector commented Oct 12, 2017

improved skill settings
==== Tech Notes ====
added capability to auto upload changes from settingsmeta.json to home.mycroft.ai

==== Documentation Notes ====
If a developer make changes to the settingsmeta.json, then this will be auto uploaded to home.mycroft.ai

NOTE: currently the auto delete of previous settingsmeta.json from device function is commented out until the api end point is implemented in the backend. For now once you make changes to the settingsmeta.json, you will have an entirely new entry in home.mycroft.ai. You will need to delete the old one manually on home.mycroft.ai.

==== Protocol Notes ====
hash and uuid are now stored as variables in files located in ~/.mycroft/skills/{skill-name}

added capability to auto upload changes from settingsmeta.json to home.mycroft.ai

====  Documentation Notes ====
If a developer make changes to the settingsmeta.json, then this will be auto uploaded to home.mycroft.ai

==== Protocol Notes ====
hash and uuid are now stored as variables in files located in ~/.mycroft/skills/{skill-name}
Copy link
Contributor

@MatthewScholefield MatthewScholefield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me. Just a few small things.

self._save_uuid(new_uuid)
self._save_hash(hashed_meta)
else: # if hash is old
should_exist_in_backend = False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be clearer to rename to something like found_in_backend?

@@ -74,80 +106,154 @@ def _is_stored(self):
return hash(str(self)) == self.loaded_hash

def __getitem__(self, key):
""" Get key
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about """ Get key """ on one line? (Same below)

sections = skill_setting['skillMetadata']['sections']
for section in sections:
for field in section["fields"]:
self.__setitem__(field["name"], field["value"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, but would it make sense to write it as:

self[field['name']] = field['value']

@@ -161,17 +267,15 @@ def load_skill_settings(self):
LOG.error(e)

def _get_settings(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hasn't been changed in this PR, but should we rename this to _get_remote_settings for clarity?

@forslund
Copy link
Collaborator

I've just skimmed the code so I might be totally off but won't the Timers hang around after skill shutdown? endlessly repeat? each time a skill is restarted a new one will occur?

Also the tail reactivated timer is quite unreliable when trying to shutdown since cancel won't work while the timed function is executed.

I'll look in more detail tomorrow morning.

@penrods penrods added the CLA: Yes Contributor License Agreement exists (see https://github.com/MycroftAI/contributors) label Oct 13, 2017
@forslund
Copy link
Collaborator

Did some basic testing and the timers are hanging around after settings goes out of scope. This means each time a skill get's reloaded another timer will be started.

The timers also hinders the process to exit cleanly, This can be quickly fix by setting the daemon property of the timers to True

Copy link
Collaborator

@forslund forslund left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See earlier comment

@LearnedVector
Copy link
Contributor Author

@forslund @MatthewScholefield fixed the timer issue. can you review

@forslund
Copy link
Collaborator

This solves part of the problem. This will allow the skill process to terminate despite timers being active.

However the Timer still seems to keep going after skill shutdown as far as I can see (and I might very well be missing something).

Probably not a big deal in most cases but not a good situation in the long run. I have an idea to deal with this using weakrefs but won't have time to deal with this tonight. I can get up early tomorrow morning and give it a go but if you think this is acceptable for this release go ahead and merge.

@MatthewScholefield
Copy link
Contributor

MatthewScholefield commented Oct 13, 2017

@forslund I'm pretty sure this won't continue after restarting the skills service because this example python code will immediately exit without printing hello:

#!/usr/bin/env python2
from __future__ import print_function
from threading import Timer


t = Timer(1, print, args=('hello',))
t.daemon = True
t.start()

@forslund
Copy link
Collaborator

Not restarting the process, that is all good. Reloading the skill. This happens when a skill is changed for example at an update.

@LearnedVector
Copy link
Contributor Author

@forslund matthew came up with an idea to set a flag in skill settings called is_alive, and we only poll if is_alive = True, on shutdown in the core.py we can call self.settings.is_alive = False, and that should stop the polling.

@forslund
Copy link
Collaborator

That will work just fine. (I really just wanted a reason to use weakrefs :) )

Add that and merge!

@forslund forslund merged commit 3e8b366 into dev Oct 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA: Yes Contributor License Agreement exists (see https://github.com/MycroftAI/contributors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants