Fas 3 steg 3a: cooking_sessions-tabell + lifecycle-endpoints + timeout-jobb, gamla /cook kvar som kortkommando
This commit is contained in:
@@ -8,6 +8,7 @@ import { processModerateRecipe } from "./processors/moderation.js";
|
||||
import { processTranslateRecipe } from "./processors/translation.js";
|
||||
import { processGenerateWeekPlan } from "./processors/weekplan.js";
|
||||
import {
|
||||
processCookingSessionTimeout,
|
||||
processExpiryNotifications,
|
||||
processMealBoxReminders,
|
||||
processMemorySync,
|
||||
@@ -117,6 +118,12 @@ const worker = new Worker(
|
||||
return;
|
||||
}
|
||||
|
||||
case "COOKING_SESSION_TIMEOUT": {
|
||||
const cancelled = await processCookingSessionTimeout(ctx);
|
||||
if (cancelled > 0) log(`Cooking session timeout: ${cancelled} avbrutna`);
|
||||
return;
|
||||
}
|
||||
|
||||
// Deterministiska/planerade jobb som inte kräver egen processor ännu
|
||||
case "NORMALIZE_PRODUCTS":
|
||||
case "DEDUPLICATE_INVENTORY":
|
||||
@@ -213,6 +220,11 @@ async function registerRepeatableJobs() {
|
||||
{ every: 6 * 60 * 60 * 1000 }, // var 6:e timme; decay lever på dygnsskala
|
||||
{ name: "UPDATE_TRUST_STATES", data: { jobType: "UPDATE_TRUST_STATES" }, opts: baseOpts },
|
||||
);
|
||||
await queue.upsertJobScheduler(
|
||||
"scheduler-cooking-timeout",
|
||||
{ every: 60 * 60 * 1000 }, // varje timme räcker för 24 h-timeout
|
||||
{ name: "COOKING_SESSION_TIMEOUT", data: { jobType: "COOKING_SESSION_TIMEOUT" }, opts: baseOpts },
|
||||
);
|
||||
await queue.upsertJobScheduler(
|
||||
"scheduler-expiry",
|
||||
{ pattern: "0 7 * * *", tz: "Europe/Stockholm" },
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { and, asc, eq, gt, inArray, isNull, lte, sql } from "drizzle-orm";
|
||||
import { and, asc, eq, gt, inArray, isNull, lt, lte, sql } from "drizzle-orm";
|
||||
import { schema } from "@app/database";
|
||||
import { classifyExpiry, computeTrust } from "@app/inventory-engine";
|
||||
import { deriveMemoryUpdates } from "@app/memory-client";
|
||||
import { getLocaleContext } from "../locale.js";
|
||||
import type { WorkerContext } from "../context.js";
|
||||
import { cancelTimedOutCookingSessions } from "@app/database";
|
||||
|
||||
/**
|
||||
* Återkommande underhållsjobb: outbox-publicering, bäst före-notiser,
|
||||
@@ -84,6 +85,12 @@ export async function processTrustDecay(ctx: WorkerContext): Promise<number> {
|
||||
return updated;
|
||||
}
|
||||
|
||||
/** COOKING_SESSION_TIMEOUT (Fas 3 §6 / §20): avbryt STARTED-sessioner äldre än 24 h. */
|
||||
export async function processCookingSessionTimeout(ctx: WorkerContext): Promise<number> {
|
||||
const sessions = await cancelTimedOutCookingSessions(ctx.db);
|
||||
return sessions.length;
|
||||
}
|
||||
|
||||
/** SEND_EXPIRY_NOTIFICATION (spec §54): skapa notiser för varor som snart går ut. */
|
||||
export async function processExpiryNotifications(ctx: WorkerContext): Promise<number> {
|
||||
const households = await ctx.db.select({ id: schema.households.id }).from(schema.households);
|
||||
|
||||
Reference in New Issue
Block a user