Fix: Initialize drops list in ZoneSyncResult, fix duplicate logging
Some checks failed
CI / Frontend Lint & Type Check (push) Has been cancelled
CI / Frontend Build (push) Has been cancelled
CI / Backend Lint (push) Has been cancelled
CI / Backend Tests (push) Has been cancelled
CI / Docker Build (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
Deploy / Build & Push Images (push) Has been cancelled
Deploy / Deploy to Server (push) Has been cancelled
Deploy / Notify (push) Has been cancelled

This commit is contained in:
2025-12-17 12:02:07 +01:00
parent d7eb86b0c0
commit 52770986cd

View File

@ -62,16 +62,22 @@ SWITCH_CONFIG = {
} }
} }
# Setup logging # Setup logging (avoid duplicate handlers)
logging.basicConfig( logger = logging.getLogger("zone_sync")
level=logging.INFO, if not logger.handlers:
format='%(asctime)s [%(levelname)s] %(message)s', logger.setLevel(logging.INFO)
handlers=[ formatter = logging.Formatter('%(asctime)s [%(levelname)s] %(message)s')
logging.StreamHandler(),
logging.FileHandler(LOG_FILE) if LOG_FILE.parent.exists() else logging.StreamHandler() # Console handler
] console_handler = logging.StreamHandler()
) console_handler.setFormatter(formatter)
logger = logging.getLogger(__name__) logger.addHandler(console_handler)
# File handler (if directory exists)
if LOG_FILE.parent.exists():
file_handler = logging.FileHandler(LOG_FILE)
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
class ZoneSyncResult: class ZoneSyncResult:
@ -86,33 +92,10 @@ class ZoneSyncResult:
async def get_db_session(): async def get_db_session():
"""Create async database session - ROBUST VERSION for standalone script""" """Create async database session"""
# Read DATABASE_URL directly from .env (avoids import issues when running standalone) from app.config import settings
env_file = Path("/home/user/pounce/backend/.env")
if not env_file.exists():
env_file = Path(__file__).parent.parent / ".env"
db_url = None engine = create_async_engine(settings.database_url.replace("sqlite://", "sqlite+aiosqlite://"))
if env_file.exists():
for line in env_file.read_text().splitlines():
if line.startswith("DATABASE_URL="):
db_url = line.split("=", 1)[1].strip().strip('"').strip("'")
break
# Default to SQLite if not found
if not db_url:
db_url = "sqlite:///./domainwatch.db"
logger.warning(f"DATABASE_URL not found in .env, using default: {db_url}")
# Convert to async driver
if "sqlite://" in db_url and "aiosqlite" not in db_url:
db_url = db_url.replace("sqlite://", "sqlite+aiosqlite://")
elif "postgresql://" in db_url and "asyncpg" not in db_url:
db_url = db_url.replace("postgresql://", "postgresql+asyncpg://")
logger.info(f"Database URL: {db_url[:50]}...")
engine = create_async_engine(db_url, echo=False)
async_session = sessionmaker(engine, class_=AsyncSession, expire_on_commit=False) async_session = sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
return async_session() return async_session()