harden database interactions and improve error handling

This commit is contained in:
ImBenji
2026-04-28 18:58:49 +01:00
parent b9f7d1ff25
commit d67a896b32
2 changed files with 8 additions and 8 deletions
+6 -6
View File
@@ -11,10 +11,11 @@ import {
} from "../utils/generateTTS";
const INTERVAL_MS = 5 * 60 * 1000;
const STALE_MINUTES = 15;
const STALE_PENDING_MINUTES = 15;
const STALE_GENERATING_MINUTES = 45; // generating can take a while for big lessons
function staleCutoff() {
return new Date(Date.now() - STALE_MINUTES * 60 * 1000).toISOString();
function staleCutoff(minutes: number) {
return new Date(Date.now() - minutes * 60 * 1000).toISOString();
}
async function repairCycle() {
@@ -49,7 +50,6 @@ async function repairCycle() {
where: eq(topics.status, "generating"),
});
const cutoff = staleCutoff();
for (const t of stuckGenerating) {
const lesson = await db.query.lessons.findFirst({ where: eq(lessons.topicId, t.id) });
@@ -93,7 +93,7 @@ async function repairCycle() {
// ── 4. stale generating branches (server died mid-branch) ────────────────
try {
const cutoff = staleCutoff();
const cutoff = staleCutoff(STALE_GENERATING_MINUTES);
const stale = await db
.update(lessons)
@@ -121,7 +121,7 @@ async function repairCycle() {
// ── 5. stale pending branches (never kicked off or abandoned) ────────────
try {
const cutoff = staleCutoff();
const cutoff = staleCutoff(STALE_PENDING_MINUTES);
const stale = await db
.update(lessons)