Fix worker crash: remove broken gunicorn post_fork hook
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+12
-10
@@ -60,16 +60,7 @@ def create_app(setup_database=True):
|
|||||||
|
|
||||||
register_cli(app)
|
register_cli(app)
|
||||||
|
|
||||||
@app.context_processor
|
# Ensure models are registered even when DB setup runs in init_db.py.
|
||||||
def inject_banners():
|
|
||||||
from app.banner_service import get_banners_by_position
|
|
||||||
|
|
||||||
try:
|
|
||||||
return {"site_banners": get_banners_by_position()}
|
|
||||||
except Exception:
|
|
||||||
return {"site_banners": {}}
|
|
||||||
|
|
||||||
if setup_database:
|
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
from app.models import ( # noqa: F401
|
from app.models import ( # noqa: F401
|
||||||
AdBanner,
|
AdBanner,
|
||||||
@@ -83,6 +74,17 @@ def create_app(setup_database=True):
|
|||||||
UserGroup,
|
UserGroup,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@app.context_processor
|
||||||
|
def inject_banners():
|
||||||
|
from app.banner_service import get_banners_by_position
|
||||||
|
|
||||||
|
try:
|
||||||
|
return {"site_banners": get_banners_by_position()}
|
||||||
|
except Exception:
|
||||||
|
return {"site_banners": {}}
|
||||||
|
|
||||||
|
if setup_database:
|
||||||
|
with app.app_context():
|
||||||
db.create_all()
|
db.create_all()
|
||||||
|
|
||||||
if os.getenv("SKIP_DB_INIT") != "1":
|
if os.getenv("SKIP_DB_INIT") != "1":
|
||||||
|
|||||||
+7
-3
@@ -2,6 +2,7 @@ import os
|
|||||||
|
|
||||||
from flask import (
|
from flask import (
|
||||||
Blueprint,
|
Blueprint,
|
||||||
|
Response,
|
||||||
abort,
|
abort,
|
||||||
current_app,
|
current_app,
|
||||||
flash,
|
flash,
|
||||||
@@ -21,6 +22,7 @@ from app.models import Folder, Photo
|
|||||||
from app.settings_service import get_settings
|
from app.settings_service import get_settings
|
||||||
from app.storage_service import delete_photo_file, get_photo_stream
|
from app.storage_service import delete_photo_file, get_photo_stream
|
||||||
from app.upload_service import process_uploads
|
from app.upload_service import process_uploads
|
||||||
|
from sqlalchemy import text
|
||||||
|
|
||||||
bp = Blueprint("main", __name__)
|
bp = Blueprint("main", __name__)
|
||||||
|
|
||||||
@@ -28,10 +30,12 @@ bp = Blueprint("main", __name__)
|
|||||||
@bp.route("/health")
|
@bp.route("/health")
|
||||||
def health():
|
def health():
|
||||||
try:
|
try:
|
||||||
db.session.execute(db.text("SELECT 1"))
|
db.session.execute(text("SELECT 1"))
|
||||||
return {"status": "ok"}, 200
|
db.session.remove()
|
||||||
|
return Response("ok\n", mimetype="text/plain")
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
return {"status": "error", "detail": str(exc)}, 503
|
db.session.remove()
|
||||||
|
return Response(f"error: {exc}\n", status=503, mimetype="text/plain")
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/")
|
@bp.route("/")
|
||||||
|
|||||||
+1
-7
@@ -3,10 +3,4 @@ workers = 2
|
|||||||
timeout = 120
|
timeout = 120
|
||||||
accesslog = "-"
|
accesslog = "-"
|
||||||
errorlog = "-"
|
errorlog = "-"
|
||||||
capture_output = True
|
loglevel = "info"
|
||||||
|
|
||||||
|
|
||||||
def post_fork(server, worker):
|
|
||||||
from app import db
|
|
||||||
|
|
||||||
db.engine.dispose()
|
|
||||||
|
|||||||
+9
-2
@@ -1,3 +1,10 @@
|
|||||||
from app import create_app
|
import sys
|
||||||
|
|
||||||
create_app(setup_database=True)
|
try:
|
||||||
|
from app import create_app
|
||||||
|
|
||||||
|
create_app(setup_database=True)
|
||||||
|
print("Database init OK", flush=True)
|
||||||
|
except Exception as exc:
|
||||||
|
print(f"Database init FAILED: {exc}", file=sys.stderr, flush=True)
|
||||||
|
raise
|
||||||
|
|||||||
Reference in New Issue
Block a user