httpapi

package
v0.3.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package httpapi is the v0.2 production API for non-Go producers (ADR-0008): enqueue tasks, report production errors (ADR-0021), and read queue stats over HTTP with token auth. Unlike the read-only dashboard (`tq serve`), this surface WRITES, so the token is mandatory on every bind (no loopback exemption: API servers are meant to be exposed to other machines).

The surface is queue-metadata plus the error-report command by design: enqueue, error.observed facts, per-status counts, and health — no per-task reads, so derived outcomes (agent results, review/status verdicts, session usage) remain dashboard surfaces (`tq serve` detail pages, `tq show`).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is the write API over one store.

func New

func New(store queue.Store, token string, log *slog.Logger) (*Server, error)

New builds a Server. token must be non-empty: the API refuses to start without one (fail closed, unlike the dashboard's loopback exemption).

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns the routed, auth-guarded API handler.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(ctx context.Context, addr string) error

ListenAndServe starts the API on addr (e.g. "127.0.0.1:8091") until ctx is cancelled. It owns the read model's lifetime when UseReadModel ran: the managed projection host tails the journal (platform restart budget and poison-fact DLQ) for the whole serve window, and the projection closes after the HTTP server has fully stopped.

func (*Server) UseErrorRecorder added in v0.3.4

func (s *Server) UseErrorRecorder(rec *incident.Recorder)

UseErrorRecorder arms POST /api/v1/errors with the ReportError command handler (ADR-0021). Without it the route answers 503, so a producer learns the surface is disabled instead of silently dropping reports. The recorder appends error.observed facts only — reactions (fix-task minting) belong to the incident policy running in the pool.

func (*Server) UseReadModel added in v0.3.1

func (s *Server) UseReadModel(ctx context.Context, d config.Deployment) error

UseReadModel moves the stats read onto the ADR-0019 S3 metaengine read model beside the deployment's queue db (readmodel.PathFor derives the projection home): the projection folds the journal and GET /api/v1/stats reads its planned table. The enqueue side is untouched — the model is read-only over the store.

The pump is the MANAGED projection host (readmodel.NewProjectionHost) built from the same readmodel seams the composition root bundles for serve: ListenAndServe starts it and owns its lifetime, a poison fact dead-letters into the best-effort DLQ sidecar (OpenDeadLetters, warn-and-continue) and the fold keeps converging, and a retryable failure restarts under the platform budget instead of wedging the cursor at repeated error logs. The model itself stays self-opened — the sanctioned per-surface exception to the composition single-opener seam (no NewProjectionRuntime adoption, no composition import, no double-close; this surface never needed the never-started runtime host, only the pump protection). Decision record: docs/memos/2026-10-10_readmodel-open-seams.md ("Residual resolved").

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL