From 251902d22c57d2649e70d7047317b0aec5ef650b Mon Sep 17 00:00:00 2001 From: aradhyacp Date: Sat, 3 Jan 2026 23:55:07 +0530 Subject: [PATCH] Skip IHDR table population and database initialization when running as a worker --- aperisolve/models.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/aperisolve/models.py b/aperisolve/models.py index 22d6d34..300f285 100644 --- a/aperisolve/models.py +++ b/aperisolve/models.py @@ -8,6 +8,7 @@ from datetime import datetime, timezone from os import getenv from pathlib import Path from shutil import rmtree +import sys from flask import Flask from flask_sqlalchemy import SQLAlchemy @@ -73,6 +74,11 @@ def fill_ihdr_db() -> None: Returns: None """ + # Skip if table already has entries + if db.session.query(IHDR.iid).first() is not None: + print("IHDR table already populated, skipping fill.") + return + # Standard PNG IHDR parameters resolutions = get_resolutions() bit_color_pairs = get_valid_depth_color_pairs() @@ -127,6 +133,12 @@ def init_db(app: Flask) -> None: - Populates the IHDR CRC lookup table with initial data - Prints status messages to console during initialization """ + # Workers should never clear/fill the database + # Detect if running as RQ worker + if 'rq.worker' in sys.modules: + print("Running as worker, skipping database initialization.") + return + with app.app_context(): if getenv("CLEAR_AT_RESTART", "0") == "1": # Force clear if CLEAR_AT_RESTART print("Clearing database and file system at restart...")