feat: externalize filter configuration and add global structured logging and job reprocessing functionality
This commit is contained in:
+17
-2
@@ -1,13 +1,13 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/hireme/hireme/internal/config"
|
||||
"github.com/hireme/hireme/internal/db"
|
||||
"github.com/hireme/hireme/internal/logger"
|
||||
"github.com/hireme/hireme/internal/worker"
|
||||
)
|
||||
|
||||
@@ -37,6 +37,7 @@ func (s *Server) RegisterRoutes(mux *http.ServeMux) {
|
||||
mux.HandleFunc("PATCH /applications/{id}/status", s.handleUpdateAppStatus)
|
||||
mux.HandleFunc("POST /api/tasks/discover", s.handleDiscoverTasks)
|
||||
mux.HandleFunc("POST /api/tasks/clean", s.handleCleanTasks)
|
||||
mux.HandleFunc("POST /api/tasks/reprocess", s.handleReprocessJobs)
|
||||
mux.HandleFunc("POST /api/tasks/toggle", s.handleToggleTasks)
|
||||
}
|
||||
|
||||
@@ -84,7 +85,7 @@ func (s *Server) handleIndex(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
if err := RenderPage(w, data); err != nil {
|
||||
log.Printf("[UI] RenderPage error: %v", err)
|
||||
logger.Log.Errorf("[UI] RenderPage error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,6 +274,7 @@ func (s *Server) handleUpdateAppStatus(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (s *Server) handleDiscoverTasks(w http.ResponseWriter, r *http.Request) {
|
||||
logger.Log.Info("[API] Triggered /api/tasks/discover")
|
||||
targets, err := s.db.GetAllTargets()
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@@ -299,6 +301,7 @@ func (s *Server) handleDiscoverTasks(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (s *Server) handleCleanTasks(w http.ResponseWriter, r *http.Request) {
|
||||
logger.Log.Info("[API] Triggered /api/tasks/clean")
|
||||
err := s.db.ClearTaskQueue()
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@@ -308,7 +311,19 @@ func (s *Server) handleCleanTasks(w http.ResponseWriter, r *http.Request) {
|
||||
_, _ = w.Write([]byte(`{"status": "success"}`))
|
||||
}
|
||||
|
||||
func (s *Server) handleReprocessJobs(w http.ResponseWriter, r *http.Request) {
|
||||
logger.Log.Info("[API] Triggered /api/tasks/reprocess")
|
||||
if err := s.db.ReprocessAllJobs(); err != nil {
|
||||
logger.Log.Errorf("[API] Failed to reprocess jobs: %v", err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write([]byte(`{"status": "success", "message": "All jobs queued for reprocessing"}`))
|
||||
}
|
||||
|
||||
func (s *Server) handleToggleTasks(w http.ResponseWriter, r *http.Request) {
|
||||
logger.Log.Info("[API] Triggered /api/tasks/toggle")
|
||||
isRunning := s.pool.Toggle()
|
||||
status := "paused"
|
||||
if isRunning {
|
||||
|
||||
@@ -193,6 +193,12 @@ const mainLayoutHTML = `{{ define "page" }}<!DOCTYPE html>
|
||||
class="relative inline-flex items-center justify-center px-3 py-1.5 text-xs font-semibold text-white transition-all bg-red-600 rounded-lg shadow-md hover:bg-red-500 active:scale-95 shadow-red-500/25">
|
||||
<span>🗑️ Clean Queue</span>
|
||||
</button>
|
||||
<button hx-post="/api/tasks/reprocess"
|
||||
hx-swap="none"
|
||||
hx-on::after-request="location.reload()"
|
||||
class="relative inline-flex items-center justify-center px-3 py-1.5 text-xs font-semibold text-white transition-all bg-amber-600 rounded-lg shadow-md hover:bg-amber-500 active:scale-95 shadow-amber-500/25">
|
||||
<span>🔄 Reprocess All Jobs</span>
|
||||
</button>
|
||||
<button hx-post="/api/tasks/toggle"
|
||||
hx-swap="none"
|
||||
hx-on::after-request="location.reload()"
|
||||
|
||||
Reference in New Issue
Block a user