feat: add job maintenance dashboard and automated stale job expiration system

This commit is contained in:
2026-08-22 01:51:43 -07:00
parent 367929e7d0
commit 7ec91f384f
12 changed files with 633 additions and 56 deletions
+35 -3
View File
@@ -55,7 +55,8 @@ func (db *DB) migrate() error {
location TEXT,
apply_url TEXT NOT NULL,
raw_content TEXT NOT NULL,
crawled_at DATETIME DEFAULT CURRENT_TIMESTAMP
crawled_at DATETIME DEFAULT CURRENT_TIMESTAMP,
last_seen_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS job_analyses (
@@ -92,6 +93,37 @@ func (db *DB) migrate() error {
);
`
_, err := db.Exec(schema)
return err
if _, err := db.Exec(schema); err != nil {
return err
}
// Dynamic migration for existing databases: check if last_seen_at exists in raw_jobs
var hasLastSeen bool
rows, err := db.Query(`PRAGMA table_info(raw_jobs)`)
if err == nil {
for rows.Next() {
var cid int
var name, ctype string
var notnull, pk int
var dfltValue sql.NullString
if err := rows.Scan(&cid, &name, &ctype, &notnull, &dfltValue, &pk); err == nil {
if name == "last_seen_at" {
hasLastSeen = true
break
}
}
}
_ = rows.Close()
}
if !hasLastSeen {
if _, err := db.Exec(`ALTER TABLE raw_jobs ADD COLUMN last_seen_at DATETIME`); err != nil {
logger.Log.Warnw("Failed to add last_seen_at column", "component", "DB", "error", err)
} else {
_, _ = db.Exec(`UPDATE raw_jobs SET last_seen_at = crawled_at WHERE last_seen_at IS NULL`)
_, _ = db.Exec(`UPDATE raw_jobs SET last_seen_at = CURRENT_TIMESTAMP WHERE last_seen_at IS NULL`)
}
}
return nil
}