Files
rsspipe/internal/api/jobs_handler.go
T
haopengzhan ebcaa5d72a
CI Quality Checks & Tests / Gitleaks Secret Detection (push) Failing after 1m59s
CI Quality Checks & Tests / Go Lint & Unit Tests (push) Failing after 2m26s
CI Quality Checks & Tests / Frontend Typecheck & Build (push) Successful in 2m37s
refactor(core): overhaul state transition architecture, persistent job queue, and API layer
- Implement atomic state transitions: add EntryService.PatchEntry() with EntryDiff computation and EventEntryTransition event emission.
- Add persistent SQLite task queue (JobEngine): add jobs table with crash recovery, exponential backoff retries, concurrency control, and idempotency key deduplication.
- Decompose monolithic HTTP handlers: split handlers.go into domain handlers (auth, feeds, entries, jobs, settings, rules, sse).
- Implement real-time Server-Sent Events (/api/events/stream) for multi-tab/device state synchronization.
- Fix SQLite concurrency: apply busy_timeout(10000) and journal_mode(WAL) via DSN query parameters to resolve SQLITE_BUSY (5).
- Fix AI settings & prompt loading: unmarshal JSON from ai_settings, apply configured prompt templates, and enforce strict enabled/API key validations.
- Fix undo share state: remove omitempty from ShareUUID to serialize null for state resets.
- Fix middle list counter: compute true unread/total stats from DB and clean switcher button labels.
- Adapt mobile UI for iOS: add viewport-fit=cover in index.html and calibrate safe-area insets for the bottom navigation and article reader toolbar.
- Add architectural documentation and worklog in docs/009_worklog.md.
2026-09-01 00:41:05 -07:00

71 lines
1.7 KiB
Go

package api
import (
"database/sql"
"net/http"
"strconv"
"git.pengzhan.dev/haopengzhan/rsspipe/internal/models"
"github.com/go-chi/chi/v5"
)
func (h *Handler) ListJobs(w http.ResponseWriter, r *http.Request) {
q := r.URL.Query()
limit, _ := strconv.Atoi(q.Get("limit"))
offset, _ := strconv.Atoi(q.Get("offset"))
filter := models.JobFilter{
Type: q.Get("type"),
Status: q.Get("status"),
Limit: limit,
Offset: offset,
}
jobs, err := h.jobService.ListJobs(r.Context(), filter)
if err != nil {
h.writeError(w, http.StatusInternalServerError, err.Error())
return
}
if jobs == nil {
jobs = []models.Job{}
}
h.writeJSON(w, http.StatusOK, map[string]interface{}{
"jobs": jobs,
"limit": limit,
"offset": offset,
})
}
func (h *Handler) GetJob(w http.ResponseWriter, r *http.Request) {
id := chi.URLParam(r, "id")
job, err := h.jobService.GetJob(r.Context(), id)
if err != nil {
if err == sql.ErrNoRows {
h.writeError(w, http.StatusNotFound, "job not found")
return
}
h.writeError(w, http.StatusInternalServerError, err.Error())
return
}
h.writeJSON(w, http.StatusOK, job)
}
func (h *Handler) CancelJob(w http.ResponseWriter, r *http.Request) {
id := chi.URLParam(r, "id")
if err := h.jobService.CancelJob(r.Context(), id); err != nil {
h.writeError(w, http.StatusInternalServerError, err.Error())
return
}
h.writeJSON(w, http.StatusOK, map[string]string{"message": "job cancelled"})
}
func (h *Handler) RetryJob(w http.ResponseWriter, r *http.Request) {
id := chi.URLParam(r, "id")
if err := h.jobService.RetryJob(r.Context(), id); err != nil {
h.writeError(w, http.StatusInternalServerError, err.Error())
return
}
h.writeJSON(w, http.StatusOK, map[string]string{"message": "job queued for retry"})
}