Merge pull request #3729 from mvdbeek/cleanup_tool_cache

Remove outdated items from tool cache when reloading the toolbox
This commit is contained in:
Dannon Baker
2017-03-17 14:12:16 -04:00
committed by GitHub
2 changed files with 18 additions and 0 deletions
+1
View File
@@ -86,6 +86,7 @@ def reload_tool(app, **kwargs):
def reload_toolbox(app, **kwargs):
log.debug("Executing toolbox reload on '%s'", app.config.server_name)
reload_count = app.toolbox._reload_count
app.tool_cache.cleanup()
app.toolbox = _get_new_toolbox(app)
app.toolbox._reload_count = reload_count + 1
+17
View File
@@ -1,3 +1,6 @@
import os
from galaxy.util.hash_util import md5_hash_file
class ToolCache(object):
@@ -7,9 +10,20 @@ class ToolCache(object):
"""
def __init__(self):
self._hash_by_tool_paths = {}
self._tools_by_path = {}
self._tool_paths_by_id = {}
def cleanup(self):
"""Remove uninstalled tools from tool cache if they are not on disk anymore or if their content has changed."""
paths_to_cleanup = {path: tool.all_ids for path, tool in self._tools_by_path.items() if not os.path.exists(path) or md5_hash_file(path) != self._hash_by_tool_paths[path]}
for config_filename, tool_ids in paths_to_cleanup.items():
del self._hash_by_tool_paths[config_filename]
del self._tools_by_path[config_filename]
for tool_id in tool_ids:
if tool_id in self._tool_paths_by_id:
del self._tool_paths_by_id[tool_id]
def get_tool(self, config_filename):
""" Get the tool from the cache if the tool is up to date.
"""
@@ -18,10 +32,13 @@ class ToolCache(object):
def expire_tool(self, tool_id):
if tool_id in self._tool_paths_by_id:
config_filename = self._tool_paths_by_id[tool_id]
del self._hash_by_tool_paths[config_filename]
del self._tool_paths_by_id[tool_id]
del self._tools_by_path[config_filename]
def cache_tool(self, config_filename, tool):
tool_hash = md5_hash_file(config_filename)
tool_id = str( tool.id )
self._hash_by_tool_paths[config_filename] = tool_hash
self._tool_paths_by_id[tool_id] = config_filename
self._tools_by_path[config_filename] = tool