Sfoglia il codice sorgente

fix: create quota_disabled flag on first run to disable quota system

Manuel 6 mesi fa
parent
commit
ca85d426f0
1 ha cambiato i file con 19 aggiunte e 1 eliminazioni
  1. 19 1
      app.py

+ 19 - 1
app.py

@@ -4,6 +4,7 @@ import signal
 import sys
 import threading
 from datetime import datetime, timedelta, timezone
+from pathlib import Path
 
 from apscheduler.schedulers.background import BackgroundScheduler
 from dotenv import load_dotenv
@@ -28,6 +29,9 @@ from services.scheduler.scheduler_tasks import register_scheduler_tasks
 from utils.filters import register_filters
 
 log_level = os.getenv("APP_LOG_LEVEL", "DEBUG" if Config.DEBUG else "INFO")
+# Remove the default loguru stderr handler before adding custom ones,
+# otherwise every message is printed twice (default + explicit add).
+logger.remove()
 logger.add(
     Config.APP_LOG,
     rotation="100 MB",
@@ -58,6 +62,15 @@ shutdown_event = threading.Event()
 
 
 def create_app():
+    # Ensure quota is disabled by default on first run (flag file must exist to disable).
+    _quota_disabled_flag = Path(__file__).resolve().parent / "quota_disabled"
+    if not _quota_disabled_flag.exists():
+        try:
+            _quota_disabled_flag.write_text("disabled\n", encoding="utf-8")
+            logger.info("Quota system disabled by default (created quota_disabled flag)")
+        except OSError as e:
+            logger.warning("Could not create quota_disabled flag: %s", e)
+
     # Run database migration at startup
     logger.info("Running database migrations with Alembic...")
     try:
@@ -260,7 +273,12 @@ def main():
 
     try:
         socketio.run(
-            app, debug=debug_mode, host=host, port=port, allow_unsafe_werkzeug=True
+            app,
+            debug=debug_mode,
+            use_reloader=False,
+            host=host,
+            port=port,
+            allow_unsafe_werkzeug=True,
         )
     except KeyboardInterrupt:
         logger.info("\n⚠️ Keyboard interrupt received")