Created
May 23, 2016 17:55
-
-
Save rday/af0df4e7f1bb6b0849631fdad0e4d5cd to your computer and use it in GitHub Desktop.
If the server drops the connection, reestablish
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// While we are supposed to be processing, make sure to reestablish the | |
// client connection if anything unexpected happens. | |
for processing { | |
ch, err := client.Watch() | |
if err != nil { | |
glog.Error(err) | |
} else { | |
validChannel := true | |
msg := Event{} | |
// While a valid channel exists, read event messages and process them | |
for validChannel { | |
select { | |
case msg, validChannel = <-ch: | |
if !validChannel { | |
glog.Warning("Channel closed by collector, restarting connection") | |
break | |
} | |
err = HandleEvent(manager, msg) | |
if err != nil { | |
if glog.V(2) { | |
glog.Error("Error handling event: ", err) | |
} | |
} | |
case <-stopCh.WaitCh(): | |
// Something told us to stop, so shutdown the processing loop | |
glog.Warning("k8s service received stop message") | |
processing = false | |
stopCh.Ack() | |
break | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment