feat(01-03): cmd/worker Phase 1 skeleton (D-03)
- 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')
This commit is contained in:
parent
08a2c3cd96
commit
aa1e1fd415
1 changed files with 48 additions and 0 deletions
48
backend/cmd/worker/main.go
Normal file
48
backend/cmd/worker/main.go
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
// 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")
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue