modcomms/cloudrun.yaml
Vadym Samoilenko a6fc149788 Replace WebSocket with REST polling to fix GCP LB 30s timeout
POST /api/analyze submits an analysis job and returns job_id instantly.
GET /api/analyze/{job_id} returns progress + result; frontend polls every 2s.

Analysis runs as asyncio.create_task in the background — each HTTP request
completes in milliseconds, well within the 30s GCP Load Balancer limit.

- Add backend/app/services/job_store.py: in-memory AnalysisJob store with
  30-min TTL cleanup
- Add backend/app/api/analysis_routes.py: POST + GET /api/analyze endpoints
  with full analysis pipeline (hash check, DB persistence, PDF pages, etc.)
- Remove backend/app/websocket/: handlers.py, manager.py, __init__.py
- Update backend/app/main.py: wire analysis_router, store analysis_service
  in app.state, drop all WebSocket imports and endpoint
- Update frontend/services/geminiService.ts: replace WS with fetch+poll;
  function signatures unchanged so App.tsx / WIPReviewer.tsx need no edits
- Remove VITE_BACKEND_WS_URL from vite.config.ts, deploy.sh, .env.deploy.example
- Update cloudrun.yaml: remove WebSocket-specific session affinity annotation

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-18 15:26:01 +00:00

74 lines
3.2 KiB
YAML

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: modcomms-backend
annotations:
# Allow unauthenticated access (frontend connects directly)
run.googleapis.com/ingress: all
spec:
template:
metadata:
annotations:
# Keep 1 instance warm to prevent cold-start latency
autoscaling.knative.dev/minScale: "1"
autoscaling.knative.dev/maxScale: "10"
# Each instance handles up to 10 concurrent analyses
autoscaling.knative.dev/target: "10"
run.googleapis.com/execution-environment: gen2
spec:
# 10-minute timeout — analysis (4 agents + lead agent) can take 2-3 minutes
# for large multi-page PDFs; 600s gives headroom without being excessive
timeoutSeconds: 600
# Gemini API calls are I/O-bound; 10 concurrent slots prevents queuing at low traffic
containerConcurrency: 10
containers:
- image: gcr.io/YOUR_PROJECT_ID/modcomms-backend:latest
ports:
- containerPort: 8000
startupProbe:
httpGet:
path: /health
port: 8000
initialDelaySeconds: 5
periodSeconds: 5
failureThreshold: 10
resources:
limits:
# 2 vCPU + 4Gi RAM: handles PDF rasterisation and parallel agent calls
cpu: "2"
memory: 4Gi
env:
# ── Gemini ────────────────────────────────────────────────────────
- name: GEMINI_API_KEY
valueFrom:
secretKeyRef:
name: gemini-api-key
key: latest
# ── Database ─────────────────────────────────────────────────────
- name: DATABASE_URL
valueFrom:
secretKeyRef:
name: database-url
key: latest
# ── Azure AD auth ─────────────────────────────────────────────────
- name: AZURE_TENANT_ID
valueFrom:
secretKeyRef:
name: azure-tenant-id
key: latest
- name: AZURE_CLIENT_ID
valueFrom:
secretKeyRef:
name: azure-client-id
key: latest
# ── App settings ──────────────────────────────────────────────────
- name: CORS_ORIGINS
value: "https://YOUR_FRONTEND_DOMAIN"
- name: HOST
value: "0.0.0.0"
- name: PORT
value: "8000"
# ── Dev/staging only ──────────────────────────────────────────────
# Uncomment to disable Azure AD auth (e.g. staging environment):
# - name: DISABLE_AUTH
# value: "true"