Release 0.15.1: schedule for the models folder scan
Release / release (push) Successful in 3m49s

Settings -> Downloads lets you scan the models folder every 2 minutes
(default, as before), hourly, daily, weekly, monthly at a chosen local
time, or only manually, with a Scan now button and the last/next scan.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Pascal LinxweilerandClaude Opus 5.5 committed 2026-10-27 16:42:56 +01:00
1 parent 276108932d
commit c6bcb514e6
14 files changed
+1940 -12

No files matched your search

+21 -4
View File
@@ -7,8 +7,9 @@ import { promisify } from "node:util";
import { and, asc, eq, inArray, isNotNull, isNull, lt, or, sql } from "drizzle-orm";
import { db } from "@/lib/db/client";
import { runMigrations } from "@/lib/db/migrate";
import { ACTIVE_JOB_STATES, type JobKind, jobFiles, jobLogs, jobs, modelFiles, models, workerState } from "@/lib/db/schema";
import { ACTIVE_JOB_STATES, type JobKind, jobFiles, jobLogs, jobs, modelFiles, models, settings, workerState } from "@/lib/db/schema";
import { coreEnv } from "@/lib/env";
import { parseScanSchedule, SCAN_SCHEDULE_KEY, scanDue } from "@/lib/folder-scan";
import { checkHub, modelsDueForHubCheck } from "@/lib/hub/availability";
import { backfillMetadata } from "@/lib/hub/refresh";
import { DeleteRunner } from "./delete";
@@ -29,7 +30,8 @@ const SHUTDOWN_GRACE_MS = 8_000;
/** How often to look for models whose Hub check is due (the check interval itself is configurable). */
const HUB_CHECK_SCAN_MS = 10 * 60_000;
/** How often MODELS_DIR is scanned for folders that could be imported (plus on request). */
const FOLDER_SCAN_MS = 2 * 60_000;
/** How often the worker checks whether a scheduled scan of MODELS_DIR is due (Settings → Downloads). */
const FOLDER_SCAN_CHECK_MS = 30_000;
const LOG_FLUSH_INTERVAL_MS = 1_000;
const BENCHMARK_TICK_MS = 2_000;
/** Touched on every heartbeat; the Docker healthcheck checks its age. */
@@ -282,6 +284,7 @@ async function scanFolders() {
lastScanStartedAt = Date.now();
try {
const n = await scanModelsDir(coreEnv().MODELS_DIR);
await db().update(workerState).set({ lastScanAt: new Date(), lastScanFound: n }).where(eq(workerState.id, "worker"));
if (n > 0) log.info(`found ${n} folder(s) in the models dir that aren't in the library`);
} catch (err) {
log.error("models dir scan failed", err);
@@ -290,6 +293,20 @@ async function scanFolders() {
}
}
/** Scan when the schedule says so; the last scan is stored, so a restart doesn't scan again early. */
async function scanIfDue() {
if (scanning || stopping) return;
try {
const [row, ws] = await Promise.all([
db().query.settings.findFirst({ where: eq(settings.key, SCAN_SCHEDULE_KEY) }),
db().query.workerState.findFirst({ columns: { lastScanAt: true }, where: eq(workerState.id, "worker") }),
]);
if (scanDue(parseScanSchedule(row?.value), ws?.lastScanAt ?? null, new Date())) await scanFolders();
} catch (err) {
log.error("scan schedule check failed", err);
}
}
let checkingHub = false;
async function checkHubDue() {
const hours = coreEnv().UPDATE_CHECK_INTERVAL_HOURS;
@@ -382,7 +399,7 @@ async function main() {
timers.push(setInterval(() => heartbeat().catch((err) => log.error("heartbeat failed", err)), HEARTBEAT_MS));
timers.push(setInterval(() => void tick(), TICK_MS));
timers.push(setInterval(() => void checkHubDue(), HUB_CHECK_SCAN_MS));
timers.push(setInterval(() => void scanFolders(), FOLDER_SCAN_MS));
timers.push(setInterval(() => void scanIfDue(), FOLDER_SCAN_CHECK_MS));
// Benchmarks: one run at a time against an endpoint.
await recoverBenchmarks();
@@ -391,7 +408,7 @@ async function main() {
timers.push(setInterval(() => void tickPublications().catch((err) => log.error("publications failed", err)), BENCHMARK_TICK_MS));
timers.push(setInterval(() => void tickBenchmarks().catch((err) => log.error("benchmarks failed", err)), BENCHMARK_TICK_MS));
timers.push(setInterval(() => void flushBenchmarkLogs().catch((err) => log.error("benchmark logs failed", err)), LOG_FLUSH_INTERVAL_MS));
void scanFolders();
void scanIfDue();
void tick();
setTimeout(() => void checkHubDue(), 15_000);
}