feat(httpapi): harden control plane and speed up prefix refresh
Очередь job получила lease и fencing, телеметрия и прогресс deploy сохраняются, ревизия пишет manifest входов. Обновление префиксов не переписывает неизменённый снимок, большие наборы идут через COPY, а устаревшая ревизия не попадает в deploy. Бандл ноды кэшируется, prune и постановка job больше не держат горячий путь. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
924f111e48
commit
f8e0520817
197 files changed
+18655
-1416
No files matched your search
@@ -0,0 +1,56 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"evobgp/internal/jobs"
|
||||
"evobgp/internal/store"
|
||||
)
|
||||
|
||||
func (s *Server) replayJobResponse(w http.ResponseWriter, r *http.Request, in store.JobEnqueue) bool {
|
||||
j, found, err := s.jobs.ReplayContext(r.Context(), in)
|
||||
if err != nil {
|
||||
writeJobEnqueueError(w, err)
|
||||
return true
|
||||
}
|
||||
if !found {
|
||||
return false
|
||||
}
|
||||
w.Header().Set("Location", "/v1/jobs/"+j.ID)
|
||||
snap := j.Snapshot()
|
||||
body := map[string]any{"job_id": j.ID, "status": snap["status"]}
|
||||
if j.Kind == jobs.KindTenantRefresh {
|
||||
ids := snap["meta"].(map[string]any)["module_ids"]
|
||||
n := 0
|
||||
switch v := ids.(type) {
|
||||
case []any:
|
||||
n = len(v)
|
||||
case []string:
|
||||
n = len(v)
|
||||
}
|
||||
body["module_ids"] = ids
|
||||
body["modules_due"] = n
|
||||
}
|
||||
writeJSON(w, http.StatusAccepted, body)
|
||||
return true
|
||||
}
|
||||
|
||||
func writeJobEnqueueError(w http.ResponseWriter, err error) {
|
||||
switch {
|
||||
case errors.Is(err, store.ErrJobConflict):
|
||||
writeProblem(w, http.StatusConflict, "Conflict", "idempotency key belongs to a different job request")
|
||||
case errors.Is(err, store.ErrJobQueueFull):
|
||||
writeProblem(w, http.StatusTooManyRequests, "Too Many Requests", "job queue is full")
|
||||
default:
|
||||
writeInternalError(w, "job_enqueue", err)
|
||||
}
|
||||
}
|
||||
|
||||
func writeJobReadError(w http.ResponseWriter, err error) {
|
||||
if errors.Is(err, jobs.ErrNotFound) || errors.Is(err, store.ErrJobNotFound) {
|
||||
writeProblem(w, http.StatusNotFound, "Not Found", "job not found")
|
||||
return
|
||||
}
|
||||
writeInternalError(w, "job_read", err)
|
||||
}
|
||||
Reference in new issue
Block a user