feat: add functionality to requeue failed jobs via API and UI interface

This commit is contained in:
2026-06-10 23:07:14 +01:00
parent 170f58067e
commit 5aa4982ca6
6 changed files with 94 additions and 1 deletions
+19
View File
@@ -195,6 +195,25 @@ func GetJobReports(limit, offset int, statusFilter string) ([]JobReport, int, er
return reports, total, nil
}
func GetJobReportByID(id int) (JobReport, error) {
var r JobReport
var targetRes, ffmpegFlags, errMsg sql.NullString
err := DB.QueryRow(`SELECT id, file_path, media_type, status, original_size, encoded_size, size_saved, processing_time, target_resolution, ffmpeg_flags, error_message, created_at FROM job_reports WHERE id = ?`, id).
Scan(&r.ID, &r.FilePath, &r.MediaType, &r.Status, &r.OriginalSize, &r.EncodedSize, &r.SizeSaved, &r.ProcessingTime, &targetRes, &ffmpegFlags, &errMsg, &r.CreatedAt)
if err != nil {
return r, err
}
if targetRes.Valid { r.TargetResolution = targetRes.String }
if ffmpegFlags.Valid { r.FFmpegFlags = ffmpegFlags.String }
if errMsg.Valid { r.ErrorMessage = errMsg.String }
return r, nil
}
func DeleteJobReport(id int) error {
_, err := DB.Exec(`DELETE FROM job_reports WHERE id = ?`, id)
return err
}
type DashboardStats struct {
TotalSavedSpace int64
FilesEncoded int
+36
View File
@@ -130,3 +130,39 @@ func (s *Server) handleDeleteWatchFolder(w http.ResponseWriter, r *http.Request)
s.wm.Reload()
w.WriteHeader(http.StatusOK)
}
func (s *Server) handleRequeueJob(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
id, err := strconv.Atoi(strings.TrimPrefix(r.URL.Path, "/api/jobs/requeue/"))
if err != nil {
http.Error(w, "Invalid ID", http.StatusBadRequest)
return
}
report, err := db.GetJobReportByID(id)
if err != nil {
http.Error(w, "Job report not found", http.StatusNotFound)
return
}
if report.Status != "failed" {
http.Error(w, "Can only requeue failed jobs", http.StatusBadRequest)
return
}
err = db.AddJob(report.FilePath, report.MediaType, 5, report.TargetResolution, report.FFmpegFlags, report.OriginalSize)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Delete the failed report so it doesn't show up in history as failed anymore
_ = db.DeleteJobReport(id)
s.qm.NotifySSE("queue_updated", nil)
s.qm.NotifySSE("job_added", nil)
w.WriteHeader(http.StatusOK)
}
+1
View File
@@ -132,6 +132,7 @@ func (s *Server) routes() {
s.mux.HandleFunc("/api/status", s.handleStatus)
s.mux.HandleFunc("/api/jobs/bump/", s.handleBumpJob)
s.mux.HandleFunc("/api/jobs/cancel/", s.handleCancelJob)
s.mux.HandleFunc("/api/jobs/requeue/", s.handleRequeueJob)
s.mux.HandleFunc("/api/folders", s.handleGetWatchFolders)
s.mux.HandleFunc("/api/folders/add", s.handleAddWatchFolder)