diff --git a/mycroft/skills/__main__.py b/mycroft/skills/__main__.py index fb6d44605a..51eff48503 100644 --- a/mycroft/skills/__main__.py +++ b/mycroft/skills/__main__.py @@ -13,6 +13,7 @@ # limitations under the License. # import time +import datetime as dt from threading import Timer import mycroft.lock from mycroft import dialog @@ -89,6 +90,14 @@ def _starting_up(): # Wait until priority skills have been loaded before checking # network connection skill_manager.load_priority() + + # If device has been offline for more than 2 weeks or + # skill state is in a limbo + update_limit = dt.datetime.now() - dt.timedelta(days=14) + if (not skill_manager.last_download or + skill_manager.last_download < update_limit): + skill_manager.download_skills(quick=True) + skill_manager.start() check_connection() diff --git a/mycroft/skills/skill_manager.py b/mycroft/skills/skill_manager.py index 1cd758b927..b3854754cd 100644 --- a/mycroft/skills/skill_manager.py +++ b/mycroft/skills/skill_manager.py @@ -15,6 +15,7 @@ import gc import sys import time +from datetime import datetime from glob import glob from itertools import chain @@ -103,9 +104,13 @@ class SkillManager(Thread): # Update immediately if the .msm or installed skills file is missing # otherwise according to timestamp on .msm if exists(self.dot_msm) and exists(self.installed_skills_file): - self.next_download = os.path.getmtime(self.dot_msm) + \ - self.update_interval + mtime = os.path.getmtime(self.dot_msm) + self.next_download = mtime + self.update_interval + self.last_download = datetime.fromtimestamp(mtime) else: + # Last update can't be found or the requirements don't seem to be + # installed trigger update before skill loading + self.last_download = None self.next_download = time.time() - 1 # Conversation management @@ -380,10 +385,6 @@ class SkillManager(Thread): # Scan the file folder that contains Skills. If a Skill is updated, # unload the existing version from memory and reload from the disk. while not self._stop_event.is_set(): - # Update skills once an hour if update is enabled - if time.time() >= self.next_download and update: - self.download_skills() - # Look for recently changed skill(s) needing a reload # checking skills dir and getting all skills there skill_paths = glob(join(self.msm.skills_dir, '*/')) @@ -406,6 +407,10 @@ class SkillManager(Thread): # Pause briefly before beginning next scan time.sleep(2) + # Update skills once an hour if update is enabled + if time.time() >= self.next_download and update: + self.download_skills() + def send_skill_list(self, message=None): """ Send list of loaded skills.