fix: SQLite WAL mode + log all swallowed 500 errors
- internal/db/db.go: Use _pragma syntax so modernc.org/sqlite actually applies busy_timeout(5000) and journal_mode(WAL). Eliminates SQLITE_BUSY 500s when concurrent reads hit a writer holding the DELETE-mode lock. - internal/api/handlers_*.go: Add slog.Error before every writeError with StatusInternalServerError so real errors appear in logs (30+ sites across handlers_jobs, handlers_machines, handlers_syncpairs, handlers_sshkeys).
This commit is contained in:
@@ -57,6 +57,7 @@ func (h *JobHandler) List(w http.ResponseWriter, r *http.Request) {
|
||||
repo := models.NewJobLogRepository(h.db)
|
||||
jobs, total, err := repo.GetAllFiltered(limit, offset, syncPairID, status, triggerType, from, to)
|
||||
if err != nil {
|
||||
slog.Error("failed to fetch jobs", "error", err)
|
||||
writeError(w, http.StatusInternalServerError, "failed to fetch jobs")
|
||||
return
|
||||
}
|
||||
@@ -83,6 +84,7 @@ func (h *JobHandler) Get(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
slog.Error("failed to fetch job", "id", id, "error", err)
|
||||
writeError(w, http.StatusInternalServerError, "failed to fetch job")
|
||||
return
|
||||
}
|
||||
@@ -103,6 +105,7 @@ func (h *JobHandler) Cancel(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
slog.Error("failed to fetch job", "id", id, "error", err)
|
||||
writeError(w, http.StatusInternalServerError, "failed to fetch job")
|
||||
return
|
||||
}
|
||||
@@ -146,6 +149,7 @@ func (h *JobHandler) TriggerRun(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
jobID, err := h.engine.CreateJob(pairID, "manual")
|
||||
if err != nil {
|
||||
slog.Error("failed to create job", "pair_id", pairID, "error", err)
|
||||
writeError(w, http.StatusInternalServerError, "failed to create job")
|
||||
return
|
||||
}
|
||||
@@ -162,6 +166,7 @@ func (h *JobHandler) TriggerRun(w http.ResponseWriter, r *http.Request) {
|
||||
jobRepo := models.NewJobRepository(h.db)
|
||||
j, err := jobRepo.GetByID(jobID)
|
||||
if err != nil {
|
||||
slog.Error("failed to fetch created job", "job_id", jobID, "error", err)
|
||||
writeError(w, http.StatusInternalServerError, "failed to fetch created job")
|
||||
return
|
||||
}
|
||||
@@ -184,6 +189,7 @@ func (h *JobHandler) GetLog(w http.ResponseWriter, r *http.Request) {
|
||||
logRepo := models.NewJobLogRepository(h.db)
|
||||
logs, err := logRepo.GetByJobID(id, limit, offset)
|
||||
if err != nil {
|
||||
slog.Error("failed to fetch logs", "id", id, "error", err)
|
||||
writeError(w, http.StatusInternalServerError, "failed to fetch logs")
|
||||
return
|
||||
}
|
||||
@@ -207,6 +213,7 @@ func (h *JobHandler) DownloadLog(w http.ResponseWriter, r *http.Request) {
|
||||
jobRepo := models.NewJobRepository(h.db)
|
||||
j, err := jobRepo.GetByID(id)
|
||||
if err != nil {
|
||||
slog.Error("failed to fetch job", "id", id, "error", err)
|
||||
writeError(w, http.StatusInternalServerError, "failed to fetch job")
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user