Skip to content

Instantly share code, notes, and snippets.

@rday
Created May 23, 2016 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rday/af0df4e7f1bb6b0849631fdad0e4d5cd to your computer and use it in GitHub Desktop.
Save rday/af0df4e7f1bb6b0849631fdad0e4d5cd to your computer and use it in GitHub Desktop.
If the server drops the connection, reestablish
// 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