- Opens pgxpool from DATABASE_URL, logs 'worker ready', blocks on SIGINT/SIGTERM, closes pool, exits 0 - Reuses web.NewSlogHandler — pure helper, no HTTP coupling - No job queue libraries (river/asynq/pg_notify) — Phase 6 replaces this file in full - 48 lines (under 80-line budget signals 'we did not implement Phase 6 by accident')
48 lines
1 KiB
Go
48 lines
1 KiB
Go
// Command worker is the Phase 1 worker skeleton (CONTEXT D-03). It boots,
|
|
// opens a pgxpool, logs "worker ready", and blocks on SIGINT/SIGTERM until
|
|
// shutdown. Phase 6 replaces this file with the real job runtime — keep it
|
|
// minimal until then.
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
|
|
"backend/internal/db"
|
|
"backend/internal/web"
|
|
)
|
|
|
|
func main() {
|
|
env := os.Getenv("ENV")
|
|
if env == "" {
|
|
env = "development"
|
|
}
|
|
dsn := os.Getenv("DATABASE_URL")
|
|
|
|
slog.SetDefault(slog.New(web.NewSlogHandler(env, os.Stdout)))
|
|
|
|
if dsn == "" {
|
|
slog.Error("DATABASE_URL is required but unset")
|
|
os.Exit(1)
|
|
}
|
|
|
|
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
|
defer stop()
|
|
|
|
pool, err := db.NewPool(ctx, dsn)
|
|
if err != nil {
|
|
slog.Error("db connect failed", "err", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
// Load-bearing signal per D-03 — verification scripts grep for this.
|
|
slog.Info("worker ready")
|
|
|
|
<-ctx.Done()
|
|
slog.Info("shutting down")
|
|
pool.Close()
|
|
slog.Info("shutdown complete")
|
|
}
|