fix: add HTTP polling fallback for selenium job results through Cloudflare
Socket.IO reconnects through Cloudflare proxy get a new socket.id, causing the backend to emit job:update to a stale socket that no longer exists. The PDF viewer modal never opened even though PDFs were saved successfully. Adds a GET /api/insurance-status/job-status/:jobId endpoint backed by InProcessQueue.getJob(), and a waitForSeleniumJob() helper on the frontend that races socket events against HTTP polling every 3s. Whichever resolves first wins, so local (socket) and external (Cloudflare) both work reliably. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -196,6 +196,13 @@ export function enqueueSeleniumJob(data: SeleniumJobData): string {
|
||||
return jobId;
|
||||
}
|
||||
|
||||
// ── Job status query (HTTP polling fallback) ─────────────────────────────────
|
||||
export function getSeleniumJobStatus(jobId: string) {
|
||||
const job = seleniumQ.getJob(jobId);
|
||||
if (!job) return null;
|
||||
return { status: job.status, result: job.result ?? null, error: job.error ?? null };
|
||||
}
|
||||
|
||||
// ── OCR enqueue ──────────────────────────────────────────────────────────────
|
||||
export function enqueueOcrJob(data: OcrJobData): string {
|
||||
const { socketId } = data;
|
||||
|
||||
@@ -15,10 +15,18 @@ import {
|
||||
} from "../../../../packages/db/types/patient-types";
|
||||
import { formatDobForAgent } from "../utils/dateUtils";
|
||||
import { seleniumQueue } from "../queue/queues";
|
||||
import { enqueueSeleniumJob } from "../queue/jobRunner";
|
||||
import { enqueueSeleniumJob, getSeleniumJobStatus } from "../queue/jobRunner";
|
||||
|
||||
const router = Router();
|
||||
|
||||
/** GET /job-status/:jobId — HTTP polling fallback when socket.io drops through Cloudflare */
|
||||
router.get("/job-status/:jobId", (req: Request, res: Response): any => {
|
||||
const jobId = String(req.params.jobId ?? "");
|
||||
const status = getSeleniumJobStatus(jobId);
|
||||
if (!status) return res.status(404).json({ error: "Job not found" });
|
||||
return res.json(status);
|
||||
});
|
||||
|
||||
/** Utility: naive name splitter */
|
||||
function splitName(fullName?: string | null) {
|
||||
if (!fullName) return { firstName: "", lastName: "" };
|
||||
|
||||
Reference in New Issue
Block a user