-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: implement
icij-worker workers start
- Loading branch information
Showing
25 changed files
with
555 additions
and
115 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from neo4j_app.icij_worker.cli import cli_app | ||
|
||
if __name__ == "__main__": | ||
cli_app() |
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,32 @@ | ||
import importlib.metadata | ||
from typing import Annotated, Optional | ||
|
||
import typer | ||
|
||
from neo4j_app.core.utils.logging import setup_loggers | ||
from neo4j_app.icij_worker.cli.workers import worker_app | ||
|
||
cli_app = typer.Typer(context_settings={"help_option_names": ["-h", "--help"]}) | ||
cli_app.add_typer(worker_app) | ||
|
||
|
||
def version_callback(value: bool): | ||
if value: | ||
import neo4j_app | ||
|
||
package_version = importlib.metadata.version(neo4j_app.__name__) | ||
print(package_version) | ||
raise typer.Exit() | ||
|
||
|
||
@cli_app.callback(name="icij-worker") | ||
def main( | ||
version: Annotated[ # pylint: disable=unused-argument | ||
Optional[bool], | ||
typer.Option( # pylint: disable=unused-argument | ||
"--version", callback=version_callback, is_eager=True | ||
), | ||
] = None, | ||
): | ||
"""Python async worker pool CLI 🧑🏭""" | ||
setup_loggers() |
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,42 @@ | ||
from pathlib import Path | ||
from typing import Annotated, Optional | ||
|
||
import typer | ||
|
||
from neo4j_app.icij_worker import AsyncApp, WorkerConfig | ||
from neo4j_app.icij_worker import WorkerBackend | ||
from neo4j_app.icij_worker.backend import start_workers | ||
|
||
|
||
_START_HELP = "Start a pool of workers running the provided app, reading the worker\ | ||
configuration from the environment or an optionally provided file." | ||
_APP_HELP = f'Path of the {AsyncApp.__name__} instance to run, fully qualified\ | ||
("module.sub.module.app_instance")' | ||
_CONFIG_HELP = f"""Path to a serialized {WorkerConfig.__name__} JSON file. | ||
By default, the configuration is read from the environment. | ||
If present, file values will override environment variables values.""" | ||
_N_HELP = "Number of workers." | ||
_BACKEND_HELP = "Python asynchronous backend used to create the worker pool." | ||
|
||
_DEFAULT_BACKEND = WorkerBackend.MULTIPROCESSING | ||
|
||
worker_app = typer.Typer(name="workers") | ||
|
||
|
||
@worker_app.command(help=_START_HELP) | ||
def start( | ||
app: Annotated[str, typer.Argument(help=_APP_HELP)], | ||
config: Annotated[ | ||
Optional[Path], typer.Option("-c", "--config", help=_CONFIG_HELP) | ||
] = None, | ||
n: Annotated[int, typer.Option("--n-workers", "-n", help=_N_HELP)] = 1, | ||
backend: Annotated[ | ||
WorkerBackend, | ||
typer.Option( | ||
help=_BACKEND_HELP, | ||
case_sensitive=False, | ||
show_default=_DEFAULT_BACKEND.value, | ||
), | ||
] = _DEFAULT_BACKEND, | ||
): | ||
start_workers(app=app, n_workers=n, config_path=config, backend=backend) |
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
Oops, something went wrong.