feat: add job maintenance dashboard and automated stale job expiration system
This commit is contained in:
+35
-3
@@ -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, ¬null, &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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user