mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-25 09:48:32 +02:00
fix(config): failed reload should not start providers in new state
This commit is contained in:
@@ -39,12 +39,12 @@ func Load() error {
|
|||||||
state := NewState()
|
state := NewState()
|
||||||
cfgWatcher = watcher.NewConfigFileWatcher(common.ConfigFileName)
|
cfgWatcher = watcher.NewConfigFileWatcher(common.ConfigFileName)
|
||||||
|
|
||||||
err := state.InitFromFileOrExit(common.ConfigPath)
|
err := errors.Join(state.InitFromFileOrExit(common.ConfigPath), state.StartProviders())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
notifyError("init", err)
|
notifyError("init", err)
|
||||||
}
|
}
|
||||||
SetState(state)
|
SetState(state)
|
||||||
return err
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func notifyError(action string, err error) {
|
func notifyError(action string, err error) {
|
||||||
@@ -72,6 +72,12 @@ func Reload() gperr.Error {
|
|||||||
// -> replace config -> start new subtasks
|
// -> replace config -> start new subtasks
|
||||||
GetState().Task().FinishAndWait("config changed")
|
GetState().Task().FinishAndWait("config changed")
|
||||||
SetState(newState)
|
SetState(newState)
|
||||||
|
|
||||||
|
if err := newState.StartProviders(); err != nil {
|
||||||
|
gperr.LogWarn("start providers error", err)
|
||||||
|
notifyError("start providers", err)
|
||||||
|
return nil // continue
|
||||||
|
}
|
||||||
StartProxyServers()
|
StartProxyServers()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,8 +108,6 @@ func (state *state) Init(data []byte) error {
|
|||||||
errs.Add(state.initNotification())
|
errs.Add(state.initNotification())
|
||||||
errs.Add(state.initAccessLogger())
|
errs.Add(state.initAccessLogger())
|
||||||
errs.Add(state.initEntrypoint())
|
errs.Add(state.initEntrypoint())
|
||||||
// this must be run after loadRouteProviders
|
|
||||||
errs.Add(state.startRouteProviders())
|
|
||||||
return errs.Error()
|
return errs.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,6 +153,16 @@ func (state *state) IterProviders() iter.Seq2[string, types.RouteProvider] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (state *state) StartProviders() error {
|
||||||
|
errs := gperr.NewGroup("provider errors")
|
||||||
|
for _, p := range state.providers.Range {
|
||||||
|
errs.Go(func() error {
|
||||||
|
return p.Start(state.Task())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return errs.Wait().Error()
|
||||||
|
}
|
||||||
|
|
||||||
func (state *state) NumProviders() int {
|
func (state *state) NumProviders() int {
|
||||||
return state.providers.Size()
|
return state.providers.Size()
|
||||||
}
|
}
|
||||||
@@ -390,13 +398,3 @@ func (state *state) printState() {
|
|||||||
l := log.Level(zerolog.InfoLevel)
|
l := log.Level(zerolog.InfoLevel)
|
||||||
yaml.NewEncoder(l).Encode(state.Config)
|
yaml.NewEncoder(l).Encode(state.Config)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (state *state) startRouteProviders() error {
|
|
||||||
errs := gperr.NewGroup("provider errors")
|
|
||||||
for _, p := range state.providers.Range {
|
|
||||||
errs.Go(func() error {
|
|
||||||
return p.Start(state.Task())
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return errs.Wait().Error()
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ type State interface {
|
|||||||
DeleteProvider(key string)
|
DeleteProvider(key string)
|
||||||
IterProviders() iter.Seq2[string, types.RouteProvider]
|
IterProviders() iter.Seq2[string, types.RouteProvider]
|
||||||
NumProviders() int
|
NumProviders() int
|
||||||
|
StartProviders() error
|
||||||
}
|
}
|
||||||
|
|
||||||
// could be nil
|
// could be nil
|
||||||
|
|||||||
Reference in New Issue
Block a user