Skip to content

Simplify the Manager API and code - #49

Merged
pior merged 5 commits into
masterfrom
manager
Feb 8, 2026
Merged

Simplify the Manager API and code#49
pior merged 5 commits into
masterfrom
manager

Conversation

@pior

@pior pior commented Feb 7, 2026

Copy link
Copy Markdown
Owner

Rewrite Manager: DAG → two-tier model

Replace the DAG-based AppManager with a simpler two-tier Manager that separates processes (foreground work) from services (infrastructure). On shutdown, processes are stopped first, then services.

New API

m := runnable.Manager().Name("app").ShutdownTimeout(30 * time.Second)
m.RegisterService(runnable.Closer(db))
m.Register(runnable.HTTPServer(server))
m.Register(jobWorker)
runnable.Run(m)
  • Manager() — constructor, returns a Runnable
  • .Register(...) — register processes (cancelled first during shutdown)
  • .RegisterService(...) — register services (cancelled after all processes stop)
  • .Name(string) — set a custom log prefix (default: "manager")
  • .ShutdownTimeout(dur) — set deadline per shutdown phase (default: 10s)
  • ManagerRegistry — interface exposing Register/RegisterService for passing to helper functions

What changed

  • manager.go — full rewrite. Two-tier run logic with context.WithoutCancel, event-driven shutdown via buffered channels (no polling ticker), two-phase cancellation
  • manager_container.go — deleted. No more per-runnable isolated contexts or DAG tracking
  • manager_test.go — 6 tests: cancellation, empty manager, dying process, dying service, shutdown timeout, shutdown ordering
  • run.goRunGroup simplified to use Manager().Register()
  • example_test.go, examples/ — updated to new API
  • README.md — updated Manager section

Removed

  • AppManager interface, Build(), Add(runnable, ...dependencies)
  • ManagerOption / ManagerShutdownTimeout() (replaced by fluent .ShutdownTimeout())
  • managerContainer, managerContainerSet (entire file)
  • Polling-based shutdown loop with 10ms ticker

Base automatically changed from naming to master February 8, 2026 10:54
@pior
pior merged commit 2e3c692 into master Feb 8, 2026
2 checks passed
@pior
pior deleted the manager branch February 8, 2026 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant