Prevent table-creation race: gunicorn --preload
With 2 workers, both ran Base.metadata.create_all() at import on an empty DB, racing on CREATE TABLE (duplicate pg_type for "projects"). --preload imports the app once in the master before forking, so tables are created a single time. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -4,5 +4,7 @@ COPY server/requirements.txt ./server/
|
|||||||
RUN pip install --no-cache-dir -r server/requirements.txt
|
RUN pip install --no-cache-dir -r server/requirements.txt
|
||||||
COPY server/ ./server/
|
COPY server/ ./server/
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
CMD ["gunicorn", "-k", "uvicorn.workers.UvicornWorker", \
|
# --preload imports the app once in the master (so create_all runs a single time)
|
||||||
|
# before forking workers, preventing a table-creation race on first startup.
|
||||||
|
CMD ["gunicorn", "-k", "uvicorn.workers.UvicornWorker", "--preload", \
|
||||||
"-b", "0.0.0.0:8000", "--workers", "2", "server.app:app"]
|
"-b", "0.0.0.0:8000", "--workers", "2", "server.app:app"]
|
||||||
Reference in New Issue
Block a user