fix(jobs): stamp job_id + user_id on verifier_checks rows (NOT NULL 23502); persist pass_through
Browse files- app/api/jobs.py +18 -4
app/api/jobs.py
CHANGED
|
@@ -29,7 +29,7 @@ import asyncio
|
|
| 29 |
import json
|
| 30 |
import logging
|
| 31 |
import time
|
| 32 |
-
from typing import List, Optional
|
| 33 |
|
| 34 |
from fastapi import APIRouter, HTTPException, Request
|
| 35 |
from pydantic import BaseModel
|
|
@@ -58,6 +58,9 @@ class JobRequest(BaseModel):
|
|
| 58 |
deep: bool = True
|
| 59 |
final: bool = True
|
| 60 |
user_id: Optional[str] = None # informational; ownership comes from the JWT
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
|
| 63 |
# ---- classification (mirror of src/lib/verifier.ts classify()) ------------
|
|
@@ -178,7 +181,7 @@ async def _finalize_failed(job_id: str, error: str, counts: dict, processed: int
|
|
| 178 |
|
| 179 |
|
| 180 |
async def _run_verifier_job(job_id: str, user_id: str, emails: List[str], deep: bool,
|
| 181 |
-
final: bool) -> None:
|
| 182 |
started = time.monotonic()
|
| 183 |
counts = {g: 0 for g in GROUPS}
|
| 184 |
processed = 0
|
|
@@ -221,7 +224,17 @@ async def _run_verifier_job(job_id: str, user_id: str, emails: List[str], deep:
|
|
| 221 |
counts, processed,
|
| 222 |
)
|
| 223 |
return
|
| 224 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
await _write_checks(rows)
|
| 226 |
for row in rows:
|
| 227 |
counts[row["grp"]] = counts.get(row["grp"], 0) + 1
|
|
@@ -306,7 +319,8 @@ async def create_server_job(request: Request, payload: JobRequest):
|
|
| 306 |
emails = payload.emails[:MAX_PER_CALL]
|
| 307 |
|
| 308 |
task = asyncio.create_task(
|
| 309 |
-
_run_verifier_job(payload.job_id, user_id, emails, payload.deep,
|
|
|
|
| 310 |
)
|
| 311 |
_job_tasks.add(task)
|
| 312 |
task.add_done_callback(_job_tasks.discard)
|
|
|
|
| 29 |
import json
|
| 30 |
import logging
|
| 31 |
import time
|
| 32 |
+
from typing import Dict, List, Optional
|
| 33 |
|
| 34 |
from fastapi import APIRouter, HTTPException, Request
|
| 35 |
from pydantic import BaseModel
|
|
|
|
| 58 |
deep: bool = True
|
| 59 |
final: bool = True
|
| 60 |
user_id: Optional[str] = None # informational; ownership comes from the JWT
|
| 61 |
+
# Per-email upload metadata the CSV carried (frontend submitServerJob sends
|
| 62 |
+
# it keyed by lowercase email). Optional + additive: predating clients omit it.
|
| 63 |
+
pass_through: Optional[Dict[str, Dict[str, str]]] = None
|
| 64 |
|
| 65 |
|
| 66 |
# ---- classification (mirror of src/lib/verifier.ts classify()) ------------
|
|
|
|
| 181 |
|
| 182 |
|
| 183 |
async def _run_verifier_job(job_id: str, user_id: str, emails: List[str], deep: bool,
|
| 184 |
+
final: bool, pass_through: Optional[dict] = None) -> None:
|
| 185 |
started = time.monotonic()
|
| 186 |
counts = {g: 0 for g in GROUPS}
|
| 187 |
processed = 0
|
|
|
|
| 224 |
counts, processed,
|
| 225 |
)
|
| 226 |
return
|
| 227 |
+
# Stamp ownership columns: verifier_checks.user_id/job_id are
|
| 228 |
+
# NOT NULL — rows without them fail the upsert (23502) and the
|
| 229 |
+
# run completes with counts but zero detail rows (2026-11-01).
|
| 230 |
+
rows = []
|
| 231 |
+
for r in results:
|
| 232 |
+
row = classify_engine_result(r)
|
| 233 |
+
row["job_id"] = job_id
|
| 234 |
+
row["user_id"] = user_id
|
| 235 |
+
if pass_through:
|
| 236 |
+
row["pass_through"] = pass_through.get((r.email or "").lower())
|
| 237 |
+
rows.append(row)
|
| 238 |
await _write_checks(rows)
|
| 239 |
for row in rows:
|
| 240 |
counts[row["grp"]] = counts.get(row["grp"], 0) + 1
|
|
|
|
| 319 |
emails = payload.emails[:MAX_PER_CALL]
|
| 320 |
|
| 321 |
task = asyncio.create_task(
|
| 322 |
+
_run_verifier_job(payload.job_id, user_id, emails, payload.deep,
|
| 323 |
+
payload.final, payload.pass_through)
|
| 324 |
)
|
| 325 |
_job_tasks.add(task)
|
| 326 |
task.add_done_callback(_job_tasks.discard)
|