Skip to content

serve

Start the control plane: HTTP API (REST + SSE + web UI), the stale-task reconciler, the worker registry, and the database migration runner.

serve
  Start the HTTP API server, reconciler, and migration runner

serve is the long-running entry point that clients and workers both depend on.

What it does on startup

In order:

  1. Open Postgres using the dsn and run the SQL migrations (golang-migrate over the embedded migrations/ set).
  2. NATS client — connect to nats_url and ensure the JetStream streams and the shared durable consumer exist.
  3. Wire the service graph — event relay hub, task store, result store, repo-config store, and the reconciler.
  4. Worker registry — subscribe to worker heartbeats so the UI can list live workers and pause/unpause them.
  5. HTTP server — start the REST API, SSE endpoint, and embedded web UI on server.host:server.port.
  6. Reconciler — start the background loop that expires tasks stuck in running.
  7. 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

# uses .go-crap-tracker.yaml or GCTD_* env vars
./go-crap-tracker serve
  • HTTP API — the endpoints serve exposes.
  • Architecture — how serve, workers, NATS, and Postgres fit together.