feat: complete v0.2 source and sync management

This commit is contained in:
2026-07-19 01:33:45 +08:00
parent 4e9a13981d
commit 5b5129fad5
21 changed files with 367 additions and 39 deletions
+16
View File
@@ -0,0 +1,16 @@
import { db } from "@/lib/db";
export type SyncTrigger = "manual" | "webhook" | "scheduled" | "source-created";
/** Queue one pull per source at a time. Returns true only when a new job was created. */
export function queuePull(sourceId: number, trigger: SyncTrigger, payload: unknown = {}) {
const result = db.prepare(`
INSERT INTO sync_jobs(source_id,kind,payload_json,trigger)
SELECT ?, 'pull', ?, ?
WHERE NOT EXISTS (
SELECT 1 FROM sync_jobs
WHERE source_id=? AND kind='pull' AND status IN ('queued','running')
)
`).run(sourceId, JSON.stringify(payload), trigger, sourceId);
return result.changes === 1;
}