Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix setting environment vars on handlers #70

Merged
merged 1 commit into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,13 @@ In ``gravity.yml`` on the job handler host::
Galaxy Job Handlers
-------------------

Gravity has limited support for reading Galaxy's job configuration: it can read statically configured job handlers in
the ``job_conf.xml`` file, but cannot read the newer YAML-format job configuration, or the job configuration inline from
``galaxy.yml``. Improved support for reading Galaxy's job configuration is planned, but for the time being, Gravity will
run standalone Galaxy job handler processes if you:
Gravity has support for reading Galaxy's job configuration: it can read statically configured job handlers in the
``job_conf.yml`` or ``job_conf.yml`` files, or the job configuration inline from the ``job_config`` option in
``galaxy.yml``. However, unless you need to statically define handlers, it is simpler to configure Gravity to run
`dynamically defined handlers`_ as detailed in the Galaxy scaling documentation.

1. Set ``job_handler_count`` to a number greater than ``0``. **NOTE:** You must also explicitly set the `job handler
assignment method`_ to ``db-skip-locked`` or ``db-transaction-isolation`` to prevent the web process from also
handling jobs. This is the preferred method for specifying job handlers.
2. Define static ``<handler id="..."/>`` handlers in the XML-format job configuration file.
When using dynamically defined handlers, be sure to explicitly set the `job handler assignment method`_ to
``db-skip-locked`` or ``db-transaction-isolation`` to prevent the web process from also handling jobs.

Configuration Precedence
------------------------
Expand Down Expand Up @@ -466,5 +464,6 @@ A ``configstate.yaml`` file for a Galaxy service might look like::
.. _FastAPI: https://fastapi.tiangolo.com/
.. _unicornherder: https://github.com/alphagov/unicornherder
.. _job handler assignment method: https://docs.galaxyproject.org/en/master/admin/scaling.html#job-handler-assignment-methods
.. _dynamically defined handlers: https://docs.galaxyproject.org/en/latest/admin/scaling.html#dynamically-defined-handlers
.. _Ansible: http://www.ansible.com/
.. _Issue #6: https://github.com/galaxyproject/gravity/issues/6
16 changes: 13 additions & 3 deletions gravity/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,12 @@ def get_config(self, conf, defaults=None):
if not exists(job_config):
job_config = None
if config.config_type == "galaxy" and job_config:
for service_name in [x["service_name"] for x in ConfigManager.get_job_config(job_config) if x["service_name"] not in webapp_service_names]:
config.services.append(service_for_service_type("standalone")(config_type=config.config_type, service_name=service_name))
for handler_settings in [x for x in ConfigManager.get_job_config(job_config) if x["service_name"] not in webapp_service_names]:
config.services.append(service_for_service_type("standalone")(
config_type=config.config_type,
service_name=handler_settings["service_name"],
environment=handler_settings.get("environment")
))

# Dynamic job handlers are configured using `job_handler_count` in galaxy.yml.
#
Expand All @@ -157,8 +161,14 @@ def create_handler_services(self, gravity_config: Settings, config):
expanded_handlers = self.expand_handlers(gravity_config, config)
for service_name, handler_settings in expanded_handlers.items():
pools = handler_settings.get('pools')
environment = handler_settings.get("environment")
config.services.append(
service_for_service_type("standalone")(config_type=config.config_type, service_name=service_name, server_pools=pools))
service_for_service_type("standalone")(
config_type=config.config_type,
service_name=service_name,
server_pools=pools,
environment=environment
))

def create_gxit_services(self, gravity_config: Settings, app_config, config):
if app_config.get("interactivetools_enable") and gravity_config.gx_it_proxy.enable:
Expand Down
3 changes: 3 additions & 0 deletions gravity/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ class GalaxyStandaloneService(Service):
command_template = "{virtualenv_bin}python ./lib/galaxy/main.py -c {galaxy_conf} --server-name={server_name}{attach_to_pool_opt}" \
" --pid-file={supervisor_state_dir}/{program_name}.pid"

def get_environment(self):
return self.get("environment") or {}


class ConfigFile(AttributeDict):
def __init__(self, *args, **kwargs):
Expand Down
5 changes: 4 additions & 1 deletion tests/test_config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ def test_preload_default(galaxy_yml, default_config_manager):

def test_register_non_default(galaxy_yml, default_config_manager):
new_bind = 'localhost:8081'
environment = {'FOO': 'foo'}
concurrency = 4
galaxy_yml.write(json.dumps({
'galaxy': None,
'gravity': {
'gunicorn': {
'bind': new_bind
'bind': new_bind,
'environment': environment
},
'celery': {
'concurrency': concurrency
Expand All @@ -58,6 +60,7 @@ def test_register_non_default(galaxy_yml, default_config_manager):
state = default_config_manager.state['config_files'][str(galaxy_yml)]
gunicorn_attributes = state['attribs']['gunicorn']
assert gunicorn_attributes['bind'] == new_bind
assert gunicorn_attributes['environment'] == environment
default_settings = Settings()
assert gunicorn_attributes['workers'] == default_settings.gunicorn.workers
celery_attributes = state['attribs']['celery']
Expand Down
12 changes: 11 additions & 1 deletion tests/test_process_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
processes:
handler0:
handler1:
environment:
BAZ: baz
sge_handler:
# Restrict a handler to load specific runners, by default they will load all.
plugins: ['sge']
Expand Down Expand Up @@ -58,10 +60,14 @@
pools:
- job-handlers
- workflow-schedulers
environment:
FOO: foo
handler1:
processes: 1
pools:
- job-handlers.special
environment:
BAR: bar
handler2:
processes: 1
pools:
Expand Down Expand Up @@ -123,9 +129,11 @@ def test_dynamic_handlers(default_config_manager, galaxy_yml, job_conf):
handler0_config = handler_config_paths[0].open().read()
assert " --server-name=handler0" in handler0_config
assert " --attach-to-pool=job-handlers --attach-to-pool=workflow-schedulers" in handler0_config
assert " FOO=foo" in handler0_config
handler1_config = handler_config_paths[1].open().read()
assert " --server-name=handler1" in handler1_config
assert " --attach-to-pool=job-handlers.special" in handler1_config
assert " BAR=bar" in handler1_config
handler2_config = handler_config_paths[2].open().read()
assert " --server-name=handler2" in handler2_config
assert " --attach-to-pool=job-handlers --attach-to-pool=job-handlers.special" in handler2_config
Expand Down Expand Up @@ -166,7 +174,9 @@ def test_static_handlers_yaml(default_config_manager, galaxy_yml, job_conf):
assert '.yml --server-name=handler0 --pid-file=' in handler0_config_path.open().read()
handler1_config_path = instance_conf_dir / 'galaxy_standalone_handler1.conf'
assert handler1_config_path.exists()
assert '.yml --server-name=handler1 --pid-file=' in handler1_config_path.open().read()
handler1_config = handler1_config_path.open().read()
assert '.yml --server-name=handler1 --pid-file=' in handler1_config
assert 'BAZ=baz' in handler1_config
assert (instance_conf_dir / 'galaxy_standalone_sge_handler.conf').exists()
assert (instance_conf_dir / 'galaxy_standalone_special_handler0.conf').exists()
assert (instance_conf_dir / 'galaxy_standalone_special_handler1.conf').exists()
Expand Down