-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add password authentication to redis connections * update tests to use the settings password * use the username and password when connecting a celery worker * use the password in the settings * try without explicit username * add cli point to create bespokefit workers * expose the cli command * add cli test * update toolkit version and pin pint * remove pint pin * fix optimised parameter caching and added test * update docs with launch-worker command
- Loading branch information
Showing
15 changed files
with
239 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import importlib | ||
|
||
import click | ||
import rich | ||
from rich import pretty | ||
|
||
from openff.bespokefit.cli.utilities import print_header | ||
from openff.bespokefit.executor.services import current_settings | ||
from openff.bespokefit.executor.utilities.celery import spawn_worker | ||
|
||
worker_types = ["fragmenter", "qc-compute", "optimizer"] | ||
|
||
|
||
@click.command("launch-worker") | ||
@click.option( | ||
"--worker-type", | ||
type=click.Choice(worker_types), | ||
help="The type of bespokefit worker to launch", | ||
required=True, | ||
) | ||
def worker_cli(worker_type: str): | ||
""" | ||
Launch a single worker of the requested type in the main process. | ||
Used to connect workers to a remote bespokefit server. | ||
Note: | ||
By default bespokefit will automatically use all cores and memory made available to the worker which should | ||
be declared in the job submission script. To change these defaults see the settings `BEFLOW_QC_COMPUTE_WORKER_N_CORES` & | ||
`BEFLOW_QC_COMPUTE_WORKER_MAX_MEM`. | ||
Args: | ||
worker_type: The alias name of the worker type which should be started. | ||
""" | ||
|
||
pretty.install() | ||
|
||
console = rich.get_console() | ||
print_header(console) | ||
|
||
worker_status = console.status(f"launching {worker_type} worker") | ||
worker_status.start() | ||
|
||
settings = current_settings() | ||
|
||
if worker_type == "fragmenter": | ||
worker_settings = settings.fragmenter_settings | ||
elif worker_type == "qc-compute": | ||
worker_settings = settings.qc_compute_settings | ||
else: | ||
worker_settings = settings.optimizer_settings | ||
|
||
worker_module = importlib.import_module(worker_settings.import_path) | ||
importlib.reload(worker_module) | ||
worker_app = getattr(worker_module, "celery_app") | ||
|
||
worker_status.stop() | ||
console.print(f"[[green]✓[/green]] bespoke {worker_type} worker launched") | ||
|
||
spawn_worker(worker_app, concurrency=1, asynchronous=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import pytest | ||
|
||
from openff.bespokefit.cli.worker import worker_cli | ||
from openff.bespokefit.executor.utilities import celery | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"worker_type", | ||
[ | ||
pytest.param("fragmenter", id="fragmenter"), | ||
pytest.param("qc-compute", id="qc-compute"), | ||
pytest.param("optimizer", id="optimizer"), | ||
], | ||
) | ||
def test_launch_worker(worker_type, runner, monkeypatch): | ||
"""Test launching a worker of the correct type, note we do not start the worker this is tested | ||
in test_celery/test_spawn_worker | ||
""" | ||
|
||
def mock_spawn(*args): | ||
return True | ||
|
||
monkeypatch.setattr(celery, "_spawn_worker", mock_spawn) | ||
|
||
output = runner.invoke(worker_cli, args=["--worker-type", worker_type]) | ||
assert output.exit_code == 0 | ||
assert worker_type in output.output |
Oops, something went wrong.