serve¶
Start the control plane: HTTP API (REST + SSE + web UI), the stale-task reconciler, the worker registry, and the database migration runner.
serve is the long-running entry point that clients and workers both depend on.
What it does on startup¶
In order:
- Open Postgres using the
dsnand run the SQL migrations (golang-migrateover the embeddedmigrations/set). - NATS client — connect to
nats_urland ensure the JetStream streams and the shared durable consumer exist. - Wire the service graph — event relay hub, task store, result store, repo-config store, and the reconciler.
- Worker registry — subscribe to worker heartbeats so the UI can list live workers and pause/unpause them.
- HTTP server — start the REST API, SSE endpoint, and embedded web UI on
server.host:server.port. - Reconciler — start the background loop that expires tasks stuck in
running. - NATS→SSE bridge — a goroutine relays task status events from NATS onto the SSE hub so subscribers see live updates.
Graceful shutdown¶
serve watches for SIGINT/SIGTERM. On signal it stops accepting new work, drains the HTTP server within server.shutdowntimeout, closes the DB, and cancels the worker/reconciler contexts.
Example¶
Related¶
- HTTP API — the endpoints
serveexposes. - Architecture — how
serve, workers, NATS, and Postgres fit together.