Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions airflow-core/src/airflow/utils/serve_logs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,8 @@ def serve_logs(port=None):
logger.info("Starting log server on %s", serve_log_uri)

# Use uvicorn directly for ASGI applications
uvicorn.run("airflow.utils.serve_logs.log_server:app", host=host, port=port, workers=2, log_level="info")
# Note: if we want to use more than 1 workers, we **can't** use the instance of FastAPI directly
# This is way we split the instantiation of log server to a separate module
#
# https://github.com/encode/uvicorn/blob/374bb6764e8d7f34abab0746857db5e3d68ecfdd/docs/deployment/index.md?plain=1#L50-L63
uvicorn.run("airflow.utils.serve_logs.log_server:get_app", host=host, port=port, log_level="info")
# Log serving is I/O bound and has low concurrency, so single process is sufficient


if __name__ == "__main__":
Expand Down
10 changes: 9 additions & 1 deletion airflow-core/src/airflow/utils/serve_logs/log_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,12 @@ def create_app():
return fastapi_app


app = create_app()
app = None


def get_app():
"""Get or create the FastAPI app instance."""
global app
if app is None:
app = create_app()
return app