From 51549d0391c4e651322ff418122fd50f3a25c8a4 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Mon, 13 Apr 2020 18:21:49 +0200 Subject: [PATCH] Only build toolbox index for webapps, delay until after startup --- lib/galaxy/app.py | 10 +++++++++- lib/galaxy/config/__init__.py | 1 - lib/galaxy/queue_worker.py | 7 +++++-- lib/galaxy/web/framework/webapp.py | 1 + lib/galaxy/webapps/galaxy/buildapp.py | 1 - lib/tool_shed/webapp/app.py | 2 ++ scripts/galaxy-main | 1 - 7 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/galaxy/app.py b/lib/galaxy/app.py index 5b13f02a54b..4a7e3c01904 100644 --- a/lib/galaxy/app.py +++ b/lib/galaxy/app.py @@ -24,7 +24,10 @@ from galaxy.managers.users import UserManager from galaxy.managers.workflows import WorkflowsManager from galaxy.model.database_heartbeat import DatabaseHeartbeat from galaxy.model.tags import GalaxyTagHandler -from galaxy.queue_worker import GalaxyQueueWorker +from galaxy.queue_worker import ( + send_local_control_task, + GalaxyQueueWorker, +) from galaxy.tool_shed.galaxy_install.installed_repository_manager import InstalledRepositoryManager from galaxy.tool_shed.galaxy_install.update_repository_manager import UpdateRepositoryManager from galaxy.tool_util.deps.views import DependencyResolversView @@ -65,6 +68,8 @@ class UniverseApplication(config.ConfiguresGalaxyMixin): logging.basicConfig(level=logging.DEBUG) log.debug("python path is: %s", ", ".join(sys.path)) self.name = 'galaxy' + # is_webapp will be set to true when building WSGI app + self.is_webapp = False self.startup_timer = ExecutionTimer() self.new_installation = False # Read config file and check for errors @@ -244,6 +249,9 @@ class UniverseApplication(config.ConfiguresGalaxyMixin): # Start web stack message handling self.application_stack.register_postfork_function(self.application_stack.start) + self.application_stack.register_postfork_function(self.queue_worker.bind_and_start) + # Delay toolbox index until after startup + self.application_stack.register_postfork_function(lambda: send_local_control_task(self, 'rebuild_toolbox_search_index')) self.model.engine.dispose() diff --git a/lib/galaxy/config/__init__.py b/lib/galaxy/config/__init__.py index bc28f5e0e01..e0412f5b188 100644 --- a/lib/galaxy/config/__init__.py +++ b/lib/galaxy/config/__init__.py @@ -1032,7 +1032,6 @@ class ConfiguresGalaxyMixin(object): self._set_enabled_container_types() index_help = getattr(self.config, "index_tool_help", True) self.toolbox_search = galaxy.tools.search.ToolBoxSearch(self.toolbox, index_help) - self.reindex_tool_search() def reindex_tool_search(self): # Call this when tools are added or removed. diff --git a/lib/galaxy/queue_worker.py b/lib/galaxy/queue_worker.py index df671acdfb9..3589ef63ed7 100644 --- a/lib/galaxy/queue_worker.py +++ b/lib/galaxy/queue_worker.py @@ -247,8 +247,11 @@ def reload_tool_data_tables(app, **kwargs): def rebuild_toolbox_search_index(app, **kwargs): - if app.toolbox_search.index_count < app.toolbox._reload_count: - app.reindex_tool_search() + if app.is_webapp: + if app.toolbox_search.index_count < app.toolbox._reload_count: + app.reindex_tool_search() + else: + log.debug("App is not a webapp, not building a search index") def reload_job_rules(app, **kwargs): diff --git a/lib/galaxy/web/framework/webapp.py b/lib/galaxy/web/framework/webapp.py index 6447ea08bd6..03b69af8bca 100644 --- a/lib/galaxy/web/framework/webapp.py +++ b/lib/galaxy/web/framework/webapp.py @@ -79,6 +79,7 @@ class WebApplication(base.WebApplication): def __init__(self, galaxy_app, session_cookie='galaxysession', name=None): self.name = name base.WebApplication.__init__(self) + galaxy_app.is_webapp = True self.set_transaction_factory(lambda e: self.transaction_chooser(e, galaxy_app, session_cookie)) # Mako support self.mako_template_lookup = self.create_mako_template_lookup(galaxy_app, name) diff --git a/lib/galaxy/webapps/galaxy/buildapp.py b/lib/galaxy/webapps/galaxy/buildapp.py index 9df4eb0ad50..8a6c0e643fe 100644 --- a/lib/galaxy/webapps/galaxy/buildapp.py +++ b/lib/galaxy/webapps/galaxy/buildapp.py @@ -204,7 +204,6 @@ uwsgi_app_factory = uwsgi_app def postfork_setup(): from galaxy.app import app - app.queue_worker.bind_and_start() app.application_stack.log_startup() diff --git a/lib/tool_shed/webapp/app.py b/lib/tool_shed/webapp/app.py index 77db4e3e236..b917d6700a4 100644 --- a/lib/tool_shed/webapp/app.py +++ b/lib/tool_shed/webapp/app.py @@ -27,6 +27,8 @@ class UniverseApplication(object): def __init__(self, **kwd): log.debug("python path is: %s", ", ".join(sys.path)) self.name = "tool_shed" + # will be overwritten when building WSGI app + self.is_webapp = False # Read the tool_shed.ini configuration file and check for errors. self.config = config.Configuration(**kwd) self.config.check() diff --git a/scripts/galaxy-main b/scripts/galaxy-main index 470d34502a0..08720d6dee0 100755 --- a/scripts/galaxy-main +++ b/scripts/galaxy-main @@ -108,7 +108,6 @@ def load_galaxy_app( **kwds ) app.database_heartbeat.start() - app.queue_worker.bind_and_start() app.application_stack.log_startup() return app