def _update_widgets(self): self._refresh(True) while not self.abortRequested(): for _ in self.tick(15, 60 * 15): # TODO: somehow delay to all other plugins loaded? unrefreshed_widgets = set() for hash, widget_ids in utils.next_cache_queue(): effected_widgets = cache_and_update(widget_ids) utils.remove_cache_queue( hash ) # Just in queued path's widget defintion has changed and it didn't update this path unrefreshed_widgets = unrefreshed_widgets.union( effected_widgets).difference(set(widget_ids)) # # wait 5s or for the skin to reload the widget # # this should reduce churn at startup where widgets take too long too long show up # before_update = time.time() # TODO: have .access file so we can put above update # while _ in self.tick(1, 10, lambda: utils.last_read(hash) > before_update): # pass # utils.log("paused queue until read {:.2} for {}".format(utils.last_read(hash)-before_update, hash[:5]), 'info') if self.abortRequested(): break for widget_id in unrefreshed_widgets: widget_def = manage.get_widget_by_id(widget_id) if not widget_def: continue _update_strings(widget_def) if self.abortRequested(): break if not self._refresh(): continue
def cache_and_update(widget_ids): """a widget might have many paths. Ensure each path is either queued for an update or is expired and if so force it to be refreshed. When going through the queue this could mean we refresh paths that other widgets also use. These will then be skipped. """ assert widget_ids effected_widgets = set() for widget_id in widget_ids: widget_def = manage.get_widget_by_id(widget_id) if not widget_def: continue changed = False widget_path = widget_def.get("path", {}) utils.log( "trying to update {} with widget def {}".format( widget_id, widget_def), "inspect", ) if type(widget_path) != list: widget_path = [widget_path] for path in widget_path: if isinstance(path, dict): _label = path["label"] path = path["file"]["file"] hash = utils.path2hash(path) # TODO: we might be updating paths used by widgets that weren't initiall queued. # We need to return those and ensure they get refreshed also. effected_widgets = effected_widgets.union( utils.widgets_for_path(path)) if utils.is_cache_queue(hash): # we need to update this path regardless new_files, files_changed = utils.cache_files(path, widget_id) changed = changed or files_changed utils.remove_cache_queue(hash) # else: # # double check this hasn't been updated already when updating another widget # expiry, _ = utils.cache_expiry(hash, widget_id, no_queue=True) # if expiry <= time.time(): # utils.cache_files(path, widget_id) # else: # pass # Skipping this path because its already been updated # TODO: only need to do that if a path has changed which we can tell from the history if changed: _update_strings(widget_def) return effected_widgets