feat: add idempotent batch task submission and recovery examples

This commit is contained in:
2026-09-17 21:21:18 +08:00
parent a8a8dcfe1e
commit 571107f96d
27 changed files with 1375 additions and 24 deletions

View File

@@ -27,6 +27,17 @@ import (
type endpoint func(*http.Request, auth.Token) (any, int, error)
func registerTasks(mux *http.ServeMux, s *service.Service) {
mux.HandleFunc("POST /v1/tasks:batch", wrap(func(r *http.Request, t auth.Token) (any, int, error) {
if len(r.Header.Values("Idempotency-Key")) != 0 {
return nil, 0, fault.Invalid("batch requires per-item idempotency_key, not an Idempotency-Key header")
}
var in service.BatchSubmitInput
if err := decodeBody(r, &in); err != nil {
return nil, 0, err
}
out, err := s.SubmitBatch(r.Context(), t, in)
return out, http.StatusOK, err
}))
mux.HandleFunc("POST /v1/tasks", wrap(func(r *http.Request, t auth.Token) (any, int, error) {
var in service.SubmitInput
if err := decodeBody(r, &in); err != nil {