Kafka consumers and WorkerPool are moved out of the server process into a dedicated worker binary. Server now handles HTTP + SSE only; worker handles Kafka consumption and AI processing. - cmd/worker/main.go + init.go: new binary with minimal config (DATABASE_URL, OPENAI_API_KEY, KAFKA_BROKERS) - cmd/server: remove WorkerPool, paidConsumer, freeConsumer - Dockerfile: builds both server and worker binaries - docker-compose.yml: add worker service - Makefile: add run-worker and docker-logs-worker targets - README.md: document worker startup and env vars Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
26 lines
706 B
Go
26 lines
706 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"github.com/food-ai/backend/internal/domain/recognition"
|
|
)
|
|
|
|
// App bundles the HTTP handler with background services that need lifecycle management.
|
|
type App struct {
|
|
handler http.Handler
|
|
sseBroker *recognition.SSEBroker
|
|
}
|
|
|
|
// ServeHTTP implements http.Handler.
|
|
func (application *App) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) {
|
|
application.handler.ServeHTTP(responseWriter, request)
|
|
}
|
|
|
|
// Start launches the SSE broker's LISTEN loop.
|
|
// Call this once before the HTTP server begins accepting connections.
|
|
func (application *App) Start(applicationContext context.Context) {
|
|
application.sseBroker.Start(applicationContext)
|
|
}
|