feat: add job maintenance dashboard and automated stale job expiration system
This commit is contained in:
@@ -2,6 +2,7 @@ package ui
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -44,6 +45,8 @@ func (s *Server) RegisterRoutes(mux *http.ServeMux) {
|
||||
mux.HandleFunc("POST /api/tasks/reprocess", s.handleReprocessJobs)
|
||||
mux.HandleFunc("POST /api/tasks/toggle", s.handleToggleTasks)
|
||||
mux.HandleFunc("GET /api/status", s.handleGetStatus)
|
||||
mux.HandleFunc("POST /api/maintenance/stale-expire", s.handleMaintenanceStaleExpire)
|
||||
mux.HandleFunc("GET /api/maintenance/stats", s.handleMaintenanceStats)
|
||||
}
|
||||
|
||||
func (s *Server) handleIndex(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -83,10 +86,16 @@ func (s *Server) handleIndex(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
mStats, err := s.db.GetJobMaintenanceStats()
|
||||
if err != nil {
|
||||
logger.Log.Warnw("Failed to get maintenance stats", "component", "UI", "error", err)
|
||||
}
|
||||
|
||||
data := PageData{
|
||||
Targets: targets,
|
||||
Jobs: jobs,
|
||||
Applications: apps,
|
||||
MaintenanceStats: mStats,
|
||||
ActiveTab: "triage",
|
||||
LLMProvider: s.cfg.LLMProvider,
|
||||
ToReviewCount: toReviewCount,
|
||||
@@ -434,3 +443,39 @@ func (s *Server) handleGetStatus(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_ = json.NewEncoder(w).Encode(resp)
|
||||
}
|
||||
|
||||
func (s *Server) handleMaintenanceStaleExpire(w http.ResponseWriter, r *http.Request) {
|
||||
if err := r.ParseForm(); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
days, _ := strconv.Atoi(r.FormValue("days"))
|
||||
if days <= 0 {
|
||||
days = 14
|
||||
}
|
||||
protect := r.FormValue("protect") != "false"
|
||||
|
||||
count, err := s.db.EnqueueExpireTasks(days, protect)
|
||||
if err != nil {
|
||||
logger.Log.Errorw("Failed to enqueue expire tasks", "component", "UI", "error", err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_ = json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
"status": "success",
|
||||
"count": count,
|
||||
"message": fmt.Sprintf("Enqueued %d expire task(s) for postings not seen in %d+ days.", count, days),
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Server) handleMaintenanceStats(w http.ResponseWriter, r *http.Request) {
|
||||
stats, err := s.db.GetJobMaintenanceStats()
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_ = json.NewEncoder(w).Encode(stats)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user