feat(eda): link binding dispatches to the captures and tasks they started

This commit is contained in:
sam committed 2026-10-05 20:16:02 +11:00
1 parent f3f73f852f
commit fcd66395cd
24 files changed
+1315 -518

No files matched your search

+24
View File
@@ -128,6 +128,30 @@ func (s *Server) handleBindingGet(w http.ResponseWriter, r *http.Request) {
writeJSON(w, b)
}
// handleDispatches serves the newest dispatch ledger rows for the resource the
// path names, linking bindings, captures and tasks to each other.
func (s *Server) handleDispatches(filterFor func(id string) (storecontract.DispatchFilter, bool)) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if s.Bindings == nil {
http.Error(w, "bindings not configured", http.StatusServiceUnavailable)
return
}
filter, ok := filterFor(r.PathValue("id"))
if !ok {
http.Error(w, "invalid id", http.StatusBadRequest)
return
}
filter.Limit = 50
dispatches, err := s.Bindings.ListDispatches(r.Context(), filter)
if err != nil {
s.Log.Error("list dispatches", "err", err)
http.Error(w, "list dispatches failed", http.StatusInternalServerError)
return
}
writeJSON(w, dispatches)
}
}
func (s *Server) handleBindingUpdate(w http.ResponseWriter, r *http.Request) {
if !s.authorizeTaskMutation(w, r) {
return
+11
View File
@@ -7,6 +7,7 @@ import (
"io/fs"
"log/slog"
"net/http"
"strconv"
"sync"
"time"
@@ -282,6 +283,16 @@ func (s *Server) registerMappingAndBindingRoutes(mux *http.ServeMux) {
mux.HandleFunc("PATCH /api/bindings/{id}", s.handleBindingUpdate)
mux.HandleFunc("DELETE /api/bindings/{id}", s.handleBindingDelete)
mux.HandleFunc("POST /api/bindings/{id}/approve", s.handleBindingApprove)
mux.HandleFunc("GET /api/bindings/{id}/dispatches", s.handleDispatches(func(id string) (storecontract.DispatchFilter, bool) {
return storecontract.DispatchFilter{BindingID: id}, id != ""
}))
mux.HandleFunc("GET /api/captures/{id}/dispatches", s.handleDispatches(func(id string) (storecontract.DispatchFilter, bool) {
return storecontract.DispatchFilter{CaptureID: id}, id != ""
}))
mux.HandleFunc("GET /api/tasks/{id}/dispatches", s.handleDispatches(func(id string) (storecontract.DispatchFilter, bool) {
taskID, err := strconv.ParseInt(id, 10, 64)
return storecontract.DispatchFilter{TaskID: taskID}, err == nil && taskID > 0
}))
mux.HandleFunc("GET /api/sources", s.handleSourcesList)
mux.HandleFunc("POST /api/sources", s.handleSourceCreate)
mux.HandleFunc("POST /api/sources/{path}/signing", s.handleSourceSigning)