Skip to content

Commit 1585557

Browse files
authored
Allow to configure log (#74)
* Allow to configure log * poetry update
1 parent c824d08 commit 1585557

File tree

4 files changed

+39
-13
lines changed

4 files changed

+39
-13
lines changed

fluid/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Reusable server side python modules"""
22

3-
__version__ = "1.6.3"
3+
__version__ = "1.6.4"

fluid/scheduler/cli.py

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from pydantic import BaseModel
1212
from rich.console import Console
1313
from rich.table import Table
14+
from typing_extensions import Annotated, Doc
1415
from uvicorn.importer import import_from_string
1516

1617
from fluid.utils import log as log_
@@ -38,19 +39,43 @@ class TaskManagerCLI(LazyGroup):
3839
def __init__(
3940
self,
4041
task_manager_app: TaskManagerApp,
42+
log_config: dict | None = None,
4143
**kwargs: Any,
4244
):
4345
kwargs.setdefault("commands", DEFAULT_COMMANDS)
4446
super().__init__(**kwargs)
45-
self.task_manager_app = task_manager_app
47+
self.task_manager_app: Annotated[
48+
TaskManagerApp,
49+
Doc(
50+
"""
51+
Task manager application.
52+
53+
This can be a FastAPI app, a callable that returns a FastAPI app,
54+
or a string import path to a FastAPI app.
55+
"""
56+
),
57+
] = task_manager_app
58+
self.log_config: Annotated[
59+
dict,
60+
Doc(
61+
"""
62+
Log configuration parameters.
63+
64+
These parameters are passed to the log_config argument of
65+
`fluid.utils.log.config()`.
66+
"""
67+
),
68+
] = (
69+
log_config or {}
70+
)
4671

4772

48-
def ctx_task_manager_app(ctx: click.Context) -> TaskManagerApp:
49-
return ctx.parent.command.task_manager_app # type: ignore
73+
def ctx_task_manager_cli(ctx: click.Context) -> TaskManagerCLI:
74+
return ctx.parent.command # type: ignore
5075

5176

5277
def ctx_app(ctx: click.Context) -> FastAPI:
53-
app = ctx_task_manager_app(ctx) # type: ignore
78+
app = ctx_task_manager_cli(ctx).task_manager_app
5479
if isinstance(app, str):
5580
return import_from_string(app)()
5681
elif isinstance(app, FastAPI):
@@ -81,7 +106,8 @@ def get_command(self, ctx: click.Context, cmd_name: str) -> click.Command | None
81106
@from_pydantic(task.params_model)
82107
def execute_task(log: bool, run_id: str, params: str, **extra: Any) -> None:
83108
if log:
84-
log_.config()
109+
log_config = ctx_task_manager_cli(ctx).log_config
110+
log_.config(**log_config)
85111
kwargs = json.loads(params or "{}")
86112
for value in extra.values():
87113
if isinstance(value, BaseModel):
@@ -132,14 +158,14 @@ def ls(ctx: click.Context) -> None:
132158
@click.pass_context
133159
def serve(ctx: click.Context, host: str, port: int, reload: bool) -> None:
134160
"""Run the service"""
135-
task_manager_app = ctx_task_manager_app(ctx)
161+
cli = ctx_task_manager_cli(ctx)
136162
uvicorn.run(
137-
task_manager_app,
163+
cli.task_manager_app,
138164
port=port,
139165
host=host,
140166
log_level="info",
141167
reload=reload,
142-
log_config=log_.config(),
168+
log_config=log_.config(**cli.log_config),
143169
)
144170

145171

poetry.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "aio-fluid"
3-
version = "1.6.3"
3+
version = "1.6.4"
44
description = "Tools for backend python services"
55
authors = [{ name = "Luca Sbardella", email = "[email protected]" }]
66
license = "BSD"

0 commit comments

Comments
 (0)