mirror of
https://github.com/ramvignesh-b/pi-ku.git
synced 2026-05-04 08:56:52 +00:00
feat: enable scheduler execution in Docker by checking UVICORN_MAIN environment variable
This commit is contained in:
+2
-1
@@ -12,4 +12,5 @@ COPY . .
|
|||||||
|
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
|
||||||
CMD ["sh", "-c", "uv run manage.py migrate && uv run gunicorn --bind 0.0.0.0:8000 --access-logfile - --error-logfile - --capture-output --log-level debug config.wsgi:application"]
|
# NOTE: Exporting env var 'UVICORN_MAIN=true' is required for the scheduler to run on app start.
|
||||||
|
CMD ["sh", "-c", "uv run manage.py migrate && UVICORN_MAIN=true uv run gunicorn --bind 0.0.0.0:8000 --access-logfile - --error-logfile - --capture-output --log-level debug config.wsgi:application"]
|
||||||
|
|||||||
@@ -10,9 +10,13 @@ class LettersConfig(AppConfig):
|
|||||||
"""
|
"""
|
||||||
Start the scheduler only when the server is starting.
|
Start the scheduler only when the server is starting.
|
||||||
NOTE: If we don't check for RUN_MAIN, the scheduler triggers for all django operations (migration, test etc.)
|
NOTE: If we don't check for RUN_MAIN, the scheduler triggers for all django operations (migration, test etc.)
|
||||||
|
NOTE++: For uvicorn, we make sure to set the env var `UVICORN_MAIN` to `true` in the docker command.
|
||||||
"""
|
"""
|
||||||
|
if not (
|
||||||
if not (os.environ.get("RUN_MAIN") == "true" or os.environ.get("WERKZEUG_RUN_MAIN") == "true"):
|
os.environ.get("RUN_MAIN") == "true"
|
||||||
|
or os.environ.get("WERKZEUG_RUN_MAIN") == "true"
|
||||||
|
or os.environ.get("UVICORN_MAIN") == "true"
|
||||||
|
):
|
||||||
return
|
return
|
||||||
from .tasks import start_scheduler
|
from .tasks import start_scheduler
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user