feat: refactor Service interface to replace Health() with Status() (string, error) for human-readable diagnostics (by AI)

This commit is contained in:
AI Engineer 2026-05-13 11:11:10 +08:00
parent 674ec88117
commit 4bf0ed1d4e
2 changed files with 11 additions and 6 deletions

View File

@ -12,8 +12,8 @@ type Service interface {
Start(ctx context.Context, logger *log.Logger) error
// Stop stops the service. It should block until the service is cleaned up.
Stop(ctx context.Context) error
// Health returns the health status of the service.
Health() error
// Status returns the current status and health of the service.
Status() (string, error)
}
// Reloader defines an optional interface for services that support configuration reloading.

View File

@ -367,11 +367,16 @@ func getInternalStatus() string {
for _, p := range priorities {
for _, ms := range services[p] {
status := shell.Green("OK")
if err := ms.svc.Health(); err != nil {
status = shell.Red(fmt.Sprintf("FAIL (%v)", err))
statusMsg, err := ms.svc.Status()
indicator := shell.Green("OK")
if err != nil {
indicator = shell.Red(fmt.Sprintf("FAIL (%v)", err))
}
if statusMsg != "" {
out += fmt.Sprintf("[%d] %-20s %s (%s)\n", p, ms.Name, indicator, statusMsg)
} else {
out += fmt.Sprintf("[%d] %-20s %s\n", p, ms.Name, indicator)
}
out += fmt.Sprintf("[%d] %-20s %s\n", p, ms.Name, status)
}
}
return out