diff --git a/internal/config/events.go b/internal/config/events.go index 79296f89..aa03d2a6 100644 --- a/internal/config/events.go +++ b/internal/config/events.go @@ -9,6 +9,7 @@ import ( "github.com/rs/zerolog" "github.com/rs/zerolog/log" "github.com/yusing/godoxy/internal/common" + config "github.com/yusing/godoxy/internal/config/types" "github.com/yusing/godoxy/internal/notif" "github.com/yusing/godoxy/internal/watcher" "github.com/yusing/godoxy/internal/watcher/events" @@ -70,7 +71,7 @@ func Reload() gperr.Error { // cancel all current subtasks -> wait // -> replace config -> start new subtasks - GetState().Task().FinishAndWait("config changed") + GetState().Task().FinishAndWait(config.ErrConfigChanged) SetState(newState) if err := newState.StartProviders(); err != nil { diff --git a/internal/config/types/state.go b/internal/config/types/state.go index 82b1d2ad..54251a0a 100644 --- a/internal/config/types/state.go +++ b/internal/config/types/state.go @@ -2,6 +2,7 @@ package config import ( "context" + "errors" "iter" "net/http" @@ -33,3 +34,5 @@ type State interface { // could be nil var ActiveState synk.Value[State] + +var ErrConfigChanged = errors.New("config changed") diff --git a/internal/idlewatcher/watcher.go b/internal/idlewatcher/watcher.go index 18d22518..cbfddc5f 100644 --- a/internal/idlewatcher/watcher.go +++ b/internal/idlewatcher/watcher.go @@ -11,6 +11,7 @@ import ( "github.com/rs/zerolog" "github.com/rs/zerolog/log" "github.com/yusing/ds/ordered" + config "github.com/yusing/godoxy/internal/config/types" "github.com/yusing/godoxy/internal/docker" "github.com/yusing/godoxy/internal/idlewatcher/provider" idlewatcher "github.com/yusing/godoxy/internal/idlewatcher/types" @@ -296,10 +297,12 @@ func NewWatcher(parent task.Parent, r types.Route, cfg *types.IdlewatcherConfig) go func() { cause := w.watchUntilDestroy() - if errors.Is(cause, causeContainerDestroy) || errors.Is(cause, task.ErrProgramExiting) { - watcherMapMu.Lock() - delete(watcherMap, key) - watcherMapMu.Unlock() + + watcherMapMu.Lock() + delete(watcherMap, key) + watcherMapMu.Unlock() + + if errors.Is(cause, causeContainerDestroy) || errors.Is(cause, task.ErrProgramExiting) || errors.Is(cause, config.ErrConfigChanged) { w.l.Info().Msg("idlewatcher stopped") } else if !errors.Is(cause, causeReload) { gperr.LogError("idlewatcher stopped unexpectedly", cause, &w.l)