"""Print Gmail scout state for debugging. Usage: python scripts/show_gmail_scout_state.py """ from __future__ import annotations import asyncio import sys from pathlib import Path _API_ROOT = Path(__file__).resolve().parent.parent if str(_API_ROOT) not in sys.path: sys.path.insert(0, str(_API_ROOT)) from sqlalchemy import select, func from app.db import async_session from app.models import CloudScoutConfig, ScoutTriageQueue, ScoutRunLog async def main() -> None: async with async_session() as session: scouts = ( await session.execute( select(CloudScoutConfig).where(CloudScoutConfig.provider == "gmail") ) ).scalars().all() for scout in scouts: print(f"\nScout: {scout.name} (id={scout.id})") print(f" enabled: {scout.enabled}") print(f" gmail_history_id: {scout.gmail_history_id}") print(f" gmail_watch_expires_at: {scout.gmail_watch_expires_at}") print(f" auto_trash_spam: {scout.auto_trash_spam}") print(f" last_run_at: {scout.last_run_at}") queued_count = ( await session.execute( select(func.count()) .select_from(ScoutTriageQueue) .where(ScoutTriageQueue.scout_id == scout.id) ) ).scalar() print(f" triage_queue rows: {queued_count}") run_count = ( await session.execute( select(func.count()) .select_from(ScoutRunLog) .where(ScoutRunLog.scout_id == scout.id) ) ).scalar() print(f" scout_run_logs: {run_count}") if __name__ == "__main__": asyncio.run(main())