celery-fastapi 0.1.1__tar.gz → 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {celery_fastapi-0.1.1 → celery_fastapi-0.1.2}/PKG-INFO +1 -1
- {celery_fastapi-0.1.1 → celery_fastapi-0.1.2}/celery_fastapi/cli.py +37 -1
- {celery_fastapi-0.1.1 → celery_fastapi-0.1.2}/pyproject.toml +1 -1
- {celery_fastapi-0.1.1 → celery_fastapi-0.1.2}/LICENSE +0 -0
- {celery_fastapi-0.1.1 → celery_fastapi-0.1.2}/README.md +0 -0
- {celery_fastapi-0.1.1 → celery_fastapi-0.1.2}/celery_fastapi/__init__.py +0 -0
- {celery_fastapi-0.1.1 → celery_fastapi-0.1.2}/celery_fastapi/app.py +0 -0
- {celery_fastapi-0.1.1 → celery_fastapi-0.1.2}/celery_fastapi/core.py +0 -0
- {celery_fastapi-0.1.1 → celery_fastapi-0.1.2}/celery_fastapi/py.typed +0 -0
- {celery_fastapi-0.1.1 → celery_fastapi-0.1.2}/celery_fastapi/server.py +0 -0
|
@@ -72,6 +72,30 @@ app = typer.Typer(
|
|
|
72
72
|
console = Console()
|
|
73
73
|
|
|
74
74
|
|
|
75
|
+
def _create_app_from_env() -> Any:
|
|
76
|
+
"""
|
|
77
|
+
Factory function to create FastAPI app from environment variables.
|
|
78
|
+
|
|
79
|
+
This is used when running with multiple workers or reload enabled,
|
|
80
|
+
as uvicorn requires an import string in these cases.
|
|
81
|
+
"""
|
|
82
|
+
from celery_fastapi.app import create_app
|
|
83
|
+
|
|
84
|
+
celery_app = os.environ.get("CELERY_FASTAPI_CELERY_APP")
|
|
85
|
+
prefix = os.environ.get("CELERY_FASTAPI_PREFIX", "")
|
|
86
|
+
root_path = os.environ.get("CELERY_FASTAPI_ROOT_PATH", "")
|
|
87
|
+
|
|
88
|
+
if not celery_app:
|
|
89
|
+
raise ValueError("CELERY_FASTAPI_CELERY_APP environment variable not set")
|
|
90
|
+
|
|
91
|
+
return create_app(
|
|
92
|
+
celery_app,
|
|
93
|
+
title="Celery FastAPI",
|
|
94
|
+
prefix=prefix,
|
|
95
|
+
fastapi_kwargs={"root_path": root_path} if root_path else None,
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
|
|
75
99
|
def version_callback(value: bool) -> None:
|
|
76
100
|
"""Print version and exit."""
|
|
77
101
|
if value:
|
|
@@ -374,7 +398,19 @@ def serve(
|
|
|
374
398
|
console.print("[dim]Press CTRL+C to stop[/]\n")
|
|
375
399
|
|
|
376
400
|
# Run the server
|
|
377
|
-
|
|
401
|
+
# When using workers > 1 or reload, we need to use an import string
|
|
402
|
+
if workers > 1 or reload:
|
|
403
|
+
# Set environment variables for the factory to use
|
|
404
|
+
os.environ["CELERY_FASTAPI_CELERY_APP"] = celery_app
|
|
405
|
+
os.environ["CELERY_FASTAPI_PREFIX"] = prefix
|
|
406
|
+
if root_path:
|
|
407
|
+
os.environ["CELERY_FASTAPI_ROOT_PATH"] = root_path
|
|
408
|
+
|
|
409
|
+
# Use the factory function as an import string
|
|
410
|
+
uvicorn.run("celery_fastapi.cli:_create_app_from_env", **uvicorn_config)
|
|
411
|
+
else:
|
|
412
|
+
# Single worker, can use app instance directly
|
|
413
|
+
uvicorn.run(fastapi_app, **uvicorn_config)
|
|
378
414
|
|
|
379
415
|
|
|
380
416
|
@app.command()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|