Skip to content

Commit c180142

Browse files
author
SM_SAYEED
committed
try 3
1 parent fd6375e commit c180142

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

app.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -555,28 +555,42 @@ def auto_import_uploads():
555555
#=======================================================================================================================================================================#
556556

557557
# Run-once warm-up
558-
from threading import Lock
558+
import threading
559559

560-
__startup_done = False
561-
_startup_lock = Lock()
560+
_startup_done = False
561+
_startup_lock = threading.Lock()
562562

563563
def _run_startup_tasks():
564+
"""Idempotent, best-effort startup initialization."""
564565
global _startup_done
565566
with _startup_lock:
566567
if _startup_done:
567568
return
568569
try:
569-
ensure_uploads_log_schema()
570-
except Exception as e:
571-
app.logger.warning("ensure_uploads_log_schema: %s", e)
572-
try:
573-
ensure_uploads_log_columns()
574-
except Exception as e:
575-
app.logger.warning("ensure_uploads_log_columns: %s", e)
576-
_startup_done = True
570+
try:
571+
ensure_uploads_log_schema()
572+
except Exception as e:
573+
app.logger.warning("ensure_uploads_log_schema at startup: %s", e)
574+
575+
try:
576+
ensure_uploads_log_columns()
577+
except Exception as e:
578+
app.logger.warning("ensure_uploads_log_columns at startup: %s", e)
579+
580+
# (Optional) If >> to clean up old local rows or dedupe:
581+
# try:
582+
# dedupe_uploads_log()
583+
# except Exception as e:
584+
# app.logger.warning("dedupe_uploads_log at startup: %s", e)
585+
586+
finally:
587+
_startup_done = True
577588

578589
@app.before_request
579590
def _startup_once():
591+
# Keep health checks and static super fast
592+
if request.endpoint in ("healthz", "static"):
593+
return
580594
if not _startup_done:
581595
_run_startup_tasks()
582596

0 commit comments

Comments
 (0)