Skip to content

Commit

Permalink
Unpin and update uvicorn version (#2514)
Browse files Browse the repository at this point in the history
* Unpin and update uvicorn version

* Unrelated format

* Update fixes
  • Loading branch information
jotare authored Oct 7, 2024
1 parent 67c726a commit 79c5c46
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 29 deletions.
2 changes: 1 addition & 1 deletion nucliadb/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ nucliadb-admin-assets>=1.0.0.post1224
nucliadb-node-binding>=2.26.0

# external dependencies
uvicorn<0.19.0
uvicorn
argdantic

aiohttp>=3.9.4
Expand Down
4 changes: 2 additions & 2 deletions nucliadb_telemetry/src/nucliadb_telemetry/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
from . import context

try:
from uvicorn.logging import AccessFormatter # type: ignore
from uvicorn.logging import AccessFormatter
except ImportError: # pragma: no cover
AccessFormatter = logging.Formatter
AccessFormatter = logging.Formatter # type: ignore

_BUILTIN_ATTRS = set(
[
Expand Down
2 changes: 1 addition & 1 deletion nucliadb_utils/requirements-fastapi.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fastapi>=0.95.2
uvicorn>=0.16.0,<0.19.0
starlette>=0.21.0
uvicorn
40 changes: 22 additions & 18 deletions nucliadb_utils/src/nucliadb_utils/fastapi/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import asyncio
import os
import sys
from contextlib import AbstractContextManager, nullcontext

import click
from fastapi import FastAPI
Expand All @@ -34,14 +35,11 @@


def metrics_app() -> tuple[Server, Config]:
loop_setup = "auto"

metrics_config = Config(
application_metrics,
host=running_settings.metrics_host,
port=running_settings.metrics_port,
debug=False,
loop=loop_setup,
loop="auto",
http="auto",
reload=False,
workers=1,
Expand All @@ -63,14 +61,12 @@ async def serve_metrics() -> Server:


def run_fastapi_with_metrics(application: FastAPI) -> None:
loop_setup = "auto"
metrics_server, metrics_config = metrics_app()
config = Config(
application,
host=running_settings.serving_host,
port=running_settings.serving_port,
debug=running_settings.debug,
loop=loop_setup,
loop="auto",
http="auto",
reload=False,
workers=1,
Expand Down Expand Up @@ -113,14 +109,22 @@ async def run_server_forever(server: Server, config: Config):
await start_server(server, config)
process_id = os.getpid()

server.install_signal_handlers()

message = "Started server process [%d]"
color_message = "Started server process [" + click.style("%d", fg="cyan") + "]"
logger.info(message, process_id, extra={"color_message": color_message})

if server.should_exit:
return

await server.main_loop()
await server.shutdown()
# compatibility with uvicorn<0.29
capture_signals: AbstractContextManager
if hasattr(server, "install_signal_handlers"): # pragma: no cover
server.install_signal_handlers()
capture_signals = nullcontext()
else:
# uvicorn>=0.29
capture_signals = server.capture_signals()

with capture_signals:
message = "Started server process [%d]"
color_message = "Started server process [" + click.style("%d", fg="cyan") + "]"
logger.info(message, process_id, extra={"color_message": color_message})

if server.should_exit:
return

await server.main_loop()
await server.shutdown()
14 changes: 7 additions & 7 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 79c5c46

Please sign in to comment.