mirror of
https://github.com/go-micro/go-micro.git
synced 2024-12-18 08:26:38 +02:00
fix(registry): fix watch services only first time (#2517)
This commit is contained in:
parent
9960cd1d36
commit
65a2e4ed02
9
registry/cache/cache.go
vendored
9
registry/cache/cache.go
vendored
@ -42,7 +42,7 @@ type cache struct {
|
||||
exit chan bool
|
||||
|
||||
// indicate whether its running
|
||||
running bool
|
||||
watchedRunning map[string]bool
|
||||
// status of the registry
|
||||
// used to hold onto the cache
|
||||
// in failure state
|
||||
@ -179,7 +179,7 @@ func (c *cache) get(service string) ([]*registry.Service, error) {
|
||||
c.watched[service] = true
|
||||
|
||||
// only kick it off if not running
|
||||
if !c.running {
|
||||
if !c.watchedRunning[service] {
|
||||
go c.run(service)
|
||||
}
|
||||
|
||||
@ -318,14 +318,14 @@ func (c *cache) update(res *registry.Result) {
|
||||
// it creates a new watcher if there's a problem
|
||||
func (c *cache) run(service string) {
|
||||
c.Lock()
|
||||
c.running = true
|
||||
c.watchedRunning[service] = true
|
||||
c.Unlock()
|
||||
|
||||
// reset watcher on exit
|
||||
defer func() {
|
||||
c.Lock()
|
||||
c.watched = make(map[string]bool)
|
||||
c.running = false
|
||||
c.watchedRunning[service] = false
|
||||
c.Unlock()
|
||||
}()
|
||||
|
||||
@ -478,6 +478,7 @@ func New(r registry.Registry, opts ...Option) Cache {
|
||||
Registry: r,
|
||||
opts: options,
|
||||
watched: make(map[string]bool),
|
||||
watchedRunning: make(map[string]bool),
|
||||
cache: make(map[string][]*registry.Service),
|
||||
ttls: make(map[string]time.Time),
|
||||
exit: make(chan bool),
|
||||
|
Loading…
Reference in New Issue
Block a user