Phase 9, part 6: background work shared safely between copies of the app

internal/jobs keeps named locks as leases in the database (schema 31:
locks, instances), taken with one conditional UPDATE on SQLite or Postgres,
renewed while the work runs and lapsing if its copy stops. Each background
loop's turn, sending an email, audits, discovery runs and imports run
under a lock; OAuth sign-ins under way are kept in the database. Copies
check in, and work marked running is recovered at start only when no
other copy is alive. Settings -> About lists the copies and work under
way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 07:56:47 -07:00
co-authored by Claude Opus 5.5
parent ba6114f367
commit c6c4c40600
18 changed files with 873 additions and 150 deletions
+19
View File
@@ -33,6 +33,25 @@ CREATE TABLE secrets (
key_id TEXT NOT NULL, -- which key sealed it: a fingerprint, never the key
updated_at TEXT NOT NULL
);
`,
},
// 31
{
Note: "copies of the app, and the locks that let only one of them do a job",
SQLite: `
CREATE TABLE instances (
id TEXT PRIMARY KEY, -- a copy of the app, while it runs
host TEXT NOT NULL DEFAULT '',
version TEXT NOT NULL DEFAULT '',
started_at TEXT NOT NULL,
seen_at TEXT NOT NULL -- its last check-in (every 30 seconds)
);
CREATE TABLE locks (
name TEXT PRIMARY KEY, -- the work, e.g. job:seo, outreach:send, audit:<site>
holder TEXT NOT NULL DEFAULT '', -- <instance>:<random>, or '' when free
taken_at TEXT NOT NULL DEFAULT '',
expires_at TEXT NOT NULL DEFAULT '' -- renewed while the work runs; free after it
);
`,
},
}