Files
lst_v3/backend/db/schema/prodAuditlog.lastProcessed.schema.ts
Blake Matthes 47b149d1ea
All checks were successful
Build and Push LST Docker Image / docker (push) Successful in 4m26s
feat(dm): migrated all the dm topics
2026-06-26 11:05:17 -05:00

40 lines
1.0 KiB
TypeScript

import { integer, pgTable, timestamp } from "drizzle-orm/pg-core";
export const prodAuditLogState = pgTable("prod_audit_log_state", {
id: integer("id").primaryKey().default(1),
lastImportedAuditId: integer("last_imported_audit_id").notNull().default(0),
lastProcessedAuditId: integer("last_processed_audit_id").notNull().default(0),
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow(),
updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow(),
});
/*
if the system fails do the process we do
and increase the retry to x max of 5 tries
const nextRetryAt = new Date(Date.now() + Math.min(30 * retryCount, 600) * 1000);
Cron every 30s
Pull ERP AuditLog by Id > lastAuditId
Insert into prod_audit_log
Postgres NOTIFY wakes worker
Worker processes pending rows
Success = success
Failure = error + retryCount + nextRetryAt
20 failures = dead + email
for the check we want to do
status IN ('pending', 'error')
AND retry_count < 20
AND (next_retry_at IS NULL OR next_retry_at <= NOW())
*/