/** * 插入一条「已超时」的 processing 记录,用于验证 timeout-sweeper * 用法:npx tsx scripts/seed-timeout-test.ts */ import { config } from "dotenv"; config(); import { Prisma } from "@prisma/client"; import { prisma } from "../lib/prisma"; const QUOTE_ID = "QTE_TIMEOUT_TEST_001"; async function main() { const backdated = new Date(Date.now() - 35_000); await prisma.quoteRecord.upsert({ where: { quoteId: QUOTE_ID }, create: { quoteId: QUOTE_ID, requestId: "timeout-test-request-id-0001", customerId: "CUST_001", cargoHash: "timeout_test_hash_000000000001", status: "processing", isRealtime: true, pickupJson: { city: "Los Angeles", state: "CA" }, deliveryJson: { city: "Dallas", state: "TX" }, weightLb: 500, dimLIn: 48, dimWIn: 40, dimHIn: 48, palletCount: 2, cargoType: "general_freight", createdAt: backdated, updatedAt: backdated, }, update: { status: "processing", errorCode: null, sourceType: null, quotesJson: Prisma.DbNull, validUntil: null, createdAt: backdated, updatedAt: backdated, }, }); console.log(`已写入测试记录 quote_id=${QUOTE_ID}(created_at 回溯 35s)`); console.log("下一步:npm run worker:scheduler -- --once"); console.log("预期:status=failed,error_code=QUOTE_TIMEOUT"); } main() .catch((error) => { console.error("写入失败:", error); process.exit(1); }) .finally(async () => { await prisma.$disconnect(); });