Add durable candidate funnel
This commit is contained in:
1 parent
5abac31c28
commit
df35648920
20 files changed
+1128
-142
No files matched your search
@@ -276,6 +276,42 @@ export function runMigrations(db: Database.Database): void {
|
||||
() => {
|
||||
addColumnIfNotExists(db, 'processed_posts', 'post_created_at', 'INTEGER');
|
||||
},
|
||||
() => db.exec(`
|
||||
CREATE TABLE IF NOT EXISTS candidate_queue (
|
||||
post_id TEXT PRIMARY KEY,
|
||||
subreddit TEXT NOT NULL,
|
||||
author TEXT NOT NULL COLLATE NOCASE,
|
||||
source_type TEXT NOT NULL CHECK(source_type IN ('image', 'chat')),
|
||||
payload_json TEXT NOT NULL,
|
||||
prepared_json TEXT,
|
||||
post_created_at INTEGER NOT NULL,
|
||||
priority REAL NOT NULL DEFAULT 1,
|
||||
status TEXT NOT NULL CHECK(status IN (
|
||||
'discovered', 'screening', 'ready', 'sending', 'retryable', 'sent', 'rejected'
|
||||
)),
|
||||
discovered_at INTEGER NOT NULL,
|
||||
updated_at INTEGER NOT NULL,
|
||||
available_at INTEGER NOT NULL,
|
||||
lease_owner TEXT,
|
||||
lease_expires_at INTEGER,
|
||||
assigned_account_id TEXT,
|
||||
attempt_count INTEGER NOT NULL DEFAULT 0,
|
||||
last_error TEXT,
|
||||
FOREIGN KEY (assigned_account_id) REFERENCES reddit_accounts(account_id) ON DELETE SET NULL
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_candidate_queue_claim
|
||||
ON candidate_queue(status, available_at, priority DESC, post_created_at DESC);
|
||||
CREATE INDEX IF NOT EXISTS idx_candidate_queue_author
|
||||
ON candidate_queue(author COLLATE NOCASE, status);
|
||||
CREATE INDEX IF NOT EXISTS idx_candidate_queue_updated
|
||||
ON candidate_queue(updated_at DESC);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS runtime_state (
|
||||
id INTEGER PRIMARY KEY CHECK(id = 1),
|
||||
bot_running INTEGER NOT NULL CHECK(bot_running IN (0, 1)),
|
||||
updated_at INTEGER NOT NULL
|
||||
);
|
||||
`),
|
||||
];
|
||||
|
||||
let currentVersion = db.pragma('user_version', { simple: true }) as number;
|
||||
|
||||
Reference in new issue
Block a user