thermograph/backend/daemon
admin_emi 5467b6e343
Some checks are pending
shell-lint / shellcheck (push) Waiting to run
Sync infra to hosts / sync-beta (push) Has been skipped
Sync infra to hosts / sync-prod (push) Has been skipped
Build + push images (Forgejo registry) / build-push (frontend) (push) Successful in 14s
Sync infra to hosts / sync-dev (push) Successful in 10s
Sync infra to hosts / sync-centralis (push) Has been skipped
Deploy / deploy (frontend) (push) Successful in 14s
secrets-guard / encrypted (push) Successful in 11s
Build + push images (Forgejo registry) / build-push (backend) (push) Successful in 1m49s
Deploy / deploy (backend) (push) Successful in 2m13s
daemon: let the conversational agent own @mentions in server channels (#59)
Co-authored-by: admin_emi <admin_emi@noreply.dev.jinemi.com>
Co-committed-by: admin_emi <admin_emi@noreply.dev.jinemi.com>
2026-08-02 01:21:04 +00:00
..
internal daemon: let the conversational agent own @mentions in server channels (#59) 2026-08-02 01:21:04 +00:00
go.mod daemon: move the Discord gateway and scheduler out of the web process into Go (#21) 2026-07-23 22:49:54 +00:00
go.sum daemon: move the Discord gateway and scheduler out of the web process into Go (#21) 2026-07-23 22:49:54 +00:00
main.go daemon: move the Discord gateway and scheduler out of the web process into Go (#21) 2026-07-23 22:49:54 +00:00
README.md daemon: move the Discord gateway and scheduler out of the web process into Go (#21) 2026-07-23 22:49:54 +00:00

thermograph-daemon

Single Go binary that owns the backend's long-lived stateful I/O: the Discord gateway connection (IDENTIFY/RESUME/heartbeat/reconnect backoff) and the recurring-job timers (warm-cities, IndexNow). It replaces the two in-process background jobs web/app.py used to run under leader election — one daemon replica makes the single-connection invariant a deployment fact instead of a runtime election.

The Go/Python split

Go here owns no climate or grading logic. Grading depends on polars and the parquet cache, and the slash-command path deliberately shares one grade builder with the API so bot grades and API grades never drift. So anything data-shaped is a POST back into the Python app's internal-only routes:

Route Purpose
POST /internal/discord/grade {"query": "phoenix"} → gateway-ready Discord message JSON, relayed to Discord verbatim
POST /internal/jobs/warm-cities trigger the warm-cities job
POST /internal/jobs/indexnow trigger the IndexNow check-and-submit

Every request carries X-Thermograph-Internal-Token. Caddy never routes /internal/* to the backend, so the token is defence in depth, not the only control. If THERMOGRAPH_INTERNAL_TOKEN is unset, the Python side disables the routes and this daemon refuses to start (fail closed on both ends).

Configuration (env)

Var Required Meaning
THERMOGRAPH_INTERNAL_TOKEN yes shared secret for the internal routes
THERMOGRAPH_API_BASE_INTERNAL yes backend base URL, e.g. http://web:8137
THERMOGRAPH_DISCORD_BOT no 1/true/yes/on enables the gateway
THERMOGRAPH_DISCORD_BOT_TOKEN no bot token (gateway stays off without it)
THERMOGRAPH_WARM_CITIES_INTERVAL_HOURS no default 24; malformed → default
THERMOGRAPH_INDEXNOW_INTERVAL_HOURS no default 6; malformed → default

Run locally

cd backend/daemon
go build ./... && go vet ./... && go test ./...

THERMOGRAPH_INTERNAL_TOKEN=dev-token \
THERMOGRAPH_API_BASE_INTERNAL=http://localhost:8137 \
go run .

Deployed as /usr/local/bin/thermograph-daemon in the backend image.