HH-442: isolate runtime processes and harden shutdown (#90)

* HH-442: isolate runtime processes and harden shutdown

* HH-442: harden worker shutdown races

* HH-442: gate dependency shutdown on active handlers

---------

Co-authored-by: Rogee <rogee@ipao.vip>
This commit is contained in:
Rogee
2026-08-22 02:38:15 +08:00
committed by GitHub
co-authored by rogee
parent 6d6d80dd86
commit 798ea43c2f
35 changed files with 1673 additions and 451 deletions
+14
View File
@@ -4,12 +4,26 @@ import (
"testing"
"github.com/gochat/gochat/internal/config"
"github.com/stretchr/testify/require"
)
func TestPrintUsage_Cov1(t *testing.T) {
printUsage()
}
func TestParseServeArgs(t *testing.T) {
workerOnly, err := parseServeArgs(nil)
require.NoError(t, err)
require.False(t, workerOnly)
workerOnly, err = parseServeArgs([]string{"--worker-only"})
require.NoError(t, err)
require.True(t, workerOnly)
_, err = parseServeArgs([]string{"--unknown"})
require.EqualError(t, err, `unknown serve option "--unknown"`)
}
func TestShouldRunSeedMigrations_True_Cov1(t *testing.T) {
cfg := &config.Config{Database: config.DatabaseConfig{RunMigrations: true}}
result := shouldRunSeedMigrations(cfg)
+25 -4
View File
@@ -35,7 +35,9 @@ func main() {
var err error
switch cmd {
case "serve", "server", "run":
err = serve()
err = serve(os.Args[2:])
case "worker":
err = serve([]string{"--worker-only"})
case "seed":
err = seed()
case "init":
@@ -53,13 +55,18 @@ func main() {
}
func printUsage() {
fmt.Println("Usage: gochat [serve|seed|init]")
fmt.Println(" serve Start the GoChat HTTP server")
fmt.Println("Usage: gochat [serve [--worker-only]|worker|seed|init]")
fmt.Println(" serve Start the GoChat HTTP server")
fmt.Println(" worker Start background workers without HTTP")
fmt.Println(" seed Create deterministic development/smoke data")
fmt.Println(" init Initialize super admin account (interactive or via flags)")
}
func serve() error {
func serve(args []string) error {
workerOnly, err := parseServeArgs(args)
if err != nil {
return err
}
env := os.Getenv("GOCHAT_ENV")
if env == "" {
env = "development"
@@ -68,9 +75,23 @@ func serve() error {
if err != nil {
return err
}
if workerOnly {
return application.RunWorker()
}
return application.Run()
}
func parseServeArgs(args []string) (bool, error) {
workerOnly := false
for _, arg := range args {
if arg != "--worker-only" {
return false, fmt.Errorf("unknown serve option %q", arg)
}
workerOnly = true
}
return workerOnly, nil
}
func seed() error {
env := os.Getenv("GOCHAT_ENV")
if env == "" {