Reorganize repo structure and standards references
This commit is contained in:
1 parent
3cb93a81be
commit
be2054274d
5885 files changed
+2588
-195
No files matched your search
@@ -0,0 +1,35 @@
|
||||
import { getSharedStore } from "./shared-store.js";
|
||||
|
||||
export interface ExportProgressSnapshot {
|
||||
processedRows: number;
|
||||
totalEstimate: number | null;
|
||||
updatedAt: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the latest export progress published by the worker job into the
|
||||
* shared store. The worker writes `export:progress:<jobId>` every N rows
|
||||
* (default 5_000) with a 1h TTL; the API surfaces that snapshot to the
|
||||
* front-end so users can poll for a row-count counter without going to
|
||||
* Postgres.
|
||||
*
|
||||
* Returns `null` when no progress entry exists (job not started, expired,
|
||||
* or never wrote any rows). Returns malformed payloads as `null` to keep
|
||||
* polling resilient against future schema changes.
|
||||
*/
|
||||
export async function readExportProgressFromSharedStore(args: { exportJobId: string; tenantId: string }): Promise<ExportProgressSnapshot | null> {
|
||||
void args.tenantId; // tenant scoping is enforced by the caller; key is global per jobId.
|
||||
const raw = await getSharedStore().get(`export:progress:${args.exportJobId}`);
|
||||
if (!raw) return null;
|
||||
try {
|
||||
const parsed = JSON.parse(raw) as Partial<ExportProgressSnapshot>;
|
||||
if (typeof parsed.processedRows !== "number") return null;
|
||||
return {
|
||||
processedRows: parsed.processedRows,
|
||||
totalEstimate: typeof parsed.totalEstimate === "number" ? parsed.totalEstimate : null,
|
||||
updatedAt: typeof parsed.updatedAt === "string" ? parsed.updatedAt : null,
|
||||
};
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user