Download skills if they're stale or in unknown state
Checks if the skills haven't been updated for more than 2 weeks or if the last_download is undefined. last_download may be undefined if the .msm file is missing or if the list of installed requirements is missing so skill requirements may be missing. This also makes sure the skills are normally loaded before the an update attemt is tried.pull/2197/head
parent
58cab5cddb
commit
cd16404455
|
@ -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()
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue