Skip to content

Commit

Permalink
fix: fix lose event bug
Browse files Browse the repository at this point in the history
  • Loading branch information
chuntaojun committed Dec 1, 2021
1 parent 4aa2aa1 commit ba2cc45
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions registry/polaris/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,36 +85,32 @@ func (watcher *PolarisServiceWatcher) startWatch() {

select {
case event := <-resp.EventChannel:
var changeEvent *config_center.ConfigChangeEvent
eType := event.GetSubScribeEventType()
if eType == api.EventInstance {
insEvent := event.(*model.InstanceEvent)
if insEvent.AddEvent != nil {
changeEvent = &config_center.ConfigChangeEvent{
watcher.notifyAllSubscriber(&config_center.ConfigChangeEvent{
Value: insEvent.AddEvent.Instances,
ConfigType: remoting.EventTypeAdd,
}
})
}
if insEvent.UpdateEvent != nil {
instances := make([]model.Instance, len(insEvent.UpdateEvent.UpdateList))
for i := range insEvent.UpdateEvent.UpdateList {
instances[i] = insEvent.UpdateEvent.UpdateList[i].After
}
changeEvent = &config_center.ConfigChangeEvent{
watcher.notifyAllSubscriber(&config_center.ConfigChangeEvent{
Value: instances,
ConfigType: remoting.EventTypeUpdate,
}
})
}
if insEvent.DeleteEvent != nil {
changeEvent = &config_center.ConfigChangeEvent{
watcher.notifyAllSubscriber(&config_center.ConfigChangeEvent{
Value: insEvent.DeleteEvent.Instances,
ConfigType: remoting.EventTypeDel,
}
})
}
}
if changeEvent != nil {
watcher.notifyAllSubscriber(changeEvent)
}
}
}
}
Expand Down

0 comments on commit ba2cc45

Please sign in to comment.