Skip IHDR table population and database initialization when running as a worker

This commit is contained in:
aradhyacp
2026-01-03 23:55:07 +05:30
parent cc0da50353
commit 251902d22c
+12
View File
@@ -8,6 +8,7 @@ from datetime import datetime, timezone
from os import getenv from os import getenv
from pathlib import Path from pathlib import Path
from shutil import rmtree from shutil import rmtree
import sys
from flask import Flask from flask import Flask
from flask_sqlalchemy import SQLAlchemy from flask_sqlalchemy import SQLAlchemy
@@ -73,6 +74,11 @@ def fill_ihdr_db() -> None:
Returns: Returns:
None 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 # Standard PNG IHDR parameters
resolutions = get_resolutions() resolutions = get_resolutions()
bit_color_pairs = get_valid_depth_color_pairs() 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 - Populates the IHDR CRC lookup table with initial data
- Prints status messages to console during initialization - 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(): with app.app_context():
if getenv("CLEAR_AT_RESTART", "0") == "1": # Force clear if CLEAR_AT_RESTART if getenv("CLEAR_AT_RESTART", "0") == "1": # Force clear if CLEAR_AT_RESTART
print("Clearing database and file system at restart...") print("Clearing database and file system at restart...")