fix(route): incorrect health status for idlewatcher dependencies

This commit is contained in:
yusing 2025-06-05 18:40:40 +08:00
parent 9470a14fe8
commit d240da4393
3 changed files with 10 additions and 2 deletions

View file

@ -69,8 +69,6 @@ type (
const ContextKey = "idlewatcher.watcher"
// TODO: replace -1 with neverTick
var (
watcherMap = make(map[string]*Watcher)
watcherMapMu sync.RWMutex
@ -315,6 +313,8 @@ func NewWatcher(parent task.Parent, r routes.Route, cfg *idlewatcher.Config) (*W
w.dedupDependencies()
r.SetHealthMonitor(w)
w.l = w.l.With().Strs("deps", cfg.DependsOn).Logger()
if exists {
w.l.Debug().Msg("idlewatcher reloaded")

View file

@ -366,6 +366,13 @@ func (r *Route) HealthMonitor() health.HealthMonitor {
return r.HealthMon
}
func (r *Route) SetHealthMonitor(m health.HealthMonitor) {
if r.HealthMon != nil && r.HealthMon != m {
r.HealthMon.Finish("health monitor replaced")
}
r.HealthMon = m
}
func (r *Route) IdlewatcherConfig() *idlewatcher.Config {
return r.Idlewatcher
}

View file

@ -26,6 +26,7 @@ type (
GetProvider() Provider
TargetURL() *net.URL
HealthMonitor() health.HealthMonitor
SetHealthMonitor(m health.HealthMonitor)
References() []string
Started() <-chan struct{}