feat: integrate DDMA eligibility into BullMQ queue with persistent session

- Route DDMA eligibility through InProcessQueue (concurrency=1) so it
  queues behind other selenium jobs instead of running concurrently
- New ddmaEligibilityProcessor: starts Python session, polls for OTP/
  completion via socket events, saves PDF and updates patient DB
- Frontend ddma-buton-modal now uses shared app socket + job:update
  pattern (drops private socket connection)
- SeleniumService: upgrade ddma_browser_manager with credential hash
  tracking, anti-detection options, and startup session clearing;
  upgrade DDMA worker with firstName/lastName support, PDF via
  printToPDF, force-logout on credential change; upgrade helpers with
  dual OTP strategy (app API + browser polling); add /clear-ddma-session
  endpoint; reduce fixed sleeps with smart WebDriverWait

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
ff
2026-04-16 09:21:47 -04:00
parent a1cccc8716
commit 289ea426d3
9 changed files with 1429 additions and 1239 deletions

View File

@@ -12,8 +12,21 @@ import os
import time
import helpers_ddma_eligibility as hddma
# Import startup session-clear functions
from ddma_browser_manager import clear_ddma_session_on_startup
from dotenv import load_dotenv
load_dotenv()
load_dotenv()
# Clear DDMA session on startup so fresh login is required after PC restart.
# Device trust tokens are preserved so OTP is still skipped after first login.
print("=" * 50)
print("SELENIUM AGENT STARTING - CLEARING DDMA SESSION")
print("=" * 50)
clear_ddma_session_on_startup()
print("=" * 50)
print("SESSION CLEAR COMPLETE")
print("=" * 50)
app = FastAPI()
@@ -264,6 +277,21 @@ async def session_status(sid: str):
return s
# ── Session management endpoints ─────────────────────────────────────────────
@app.post("/clear-ddma-session")
async def clear_ddma_session_endpoint():
"""
Clears the DDMA browser session (cookies + cached credentials).
Call this when DDMA credentials are deleted or changed.
"""
try:
clear_ddma_session_on_startup()
return {"status": "success", "message": "DDMA session cleared"}
except Exception as e:
return {"status": "error", "message": str(e)}
# ✅ Health Check Endpoint
@app.get("/")
async def health_check():