Skip to content

Commit

Permalink
wtf: Improve wtf serve
Browse files Browse the repository at this point in the history
- Forward CLI options `--listen` and `--reload` to implementation
- Improve documentation about the `--listen` and `--reload` options
- Assign random port when `--listen` is supplied without port number
  • Loading branch information
amotl committed Jun 13, 2024
1 parent eee36cb commit 21b746e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion cratedb_toolkit/util/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def start_service(app: str, listen_address: t.Union[str, None] = None, reload: b
if listen_address is None:
listen_address = "127.0.0.1:4242"

host, port = listen_address.split(":")
host, _, port = listen_address.partition(":")
port = port or "0"
port_int = int(port)

logger.info(f"Starting HTTP web service on http://{listen_address}")
Expand Down
2 changes: 1 addition & 1 deletion cratedb_toolkit/wtf/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ def info(category: str, adapter: t.Annotated[DatabaseAdapter, Depends(database_a


def start(listen_address: t.Union[str, None] = None, reload: bool = False): # pragma: no cover
start_service(app="cratedb_toolkit.wtf.http:app")
start_service(app="cratedb_toolkit.wtf.http:app", listen_address=listen_address, reload=reload)
13 changes: 12 additions & 1 deletion doc/wtf/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Install.
pip install --upgrade 'cratedb-toolkit[service]'
```

Expose collected status information.
Expose collected status information.
```shell
cratedb-wtf --debug serve --reload
```
Expand All @@ -60,6 +60,17 @@ Consume collected status information via HTTP.
http http://127.0.0.1:4242/info/all
```

Make the service listen on a specific address.
```shell
ctk wtf serve --listen 0.0.0.0:8042
```

:::{note}
The `--reload` option is suitable for development scenarios where you intend
to have the changes to the code become available while editing, in near
real-time.
:::


```{toctree}
:maxdepth: 1
Expand Down

0 comments on commit 21b746e

Please sign in to comment.