Fas 3 steg 3a: cooking_sessions-tabell + lifecycle-endpoints + timeout-jobb, gamla /cook kvar som kortkommando

This commit is contained in:
Sven (AAMOS AI)
2026-08-07 03:14:13 +07:00
parent 4a4f448e1c
commit e9fb4a17d4
17 changed files with 10619 additions and 196 deletions
+23
View File
@@ -0,0 +1,23 @@
import { and, eq, lt } from "drizzle-orm";
import * as schema from "./schema/index.js";
const SESSION_TIMEOUT_MS = 24 * 60 * 60 * 1000;
/**
* Timeout-jobb (Fas 3 §6 / §20): avbryt STARTED-sessioner äldre än 24 h utan complete.
* PLANNED reserverar aldrig lager, så den behöver ingen timeout.
*/
export async function cancelTimedOutCookingSessions(db: { update: Function }) {
const deadline = new Date(Date.now() - SESSION_TIMEOUT_MS);
const sessions = await db
.update(schema.cookingSessions)
.set({ status: "cancelled", cancelledAt: new Date(), updatedAt: new Date() })
.where(
and(
eq(schema.cookingSessions.status, "started"),
lt(schema.cookingSessions.startedAt, deadline),
),
)
.returning();
return sessions;
}