zookeeper: Gracefully close connection when app is shutting down.

This should help reduce logspam on the zookeeper ensemble.

The `on_app_shutdown` function is intended for use in gunicorn's
`worker_exit` hook.
This commit is contained in:
Neil Williams
2014-12-16 22:20:22 -08:00
parent 224cce72c7
commit ee2ae1ed3a

View File

@@ -135,6 +135,12 @@ class PermissionFilteredEmployeeList(object):
return "<PermissionFilteredEmployeeList %r>" % (list(self),)
SHUTDOWN_CALLBACKS = []
def on_app_shutdown(arbiter, worker):
for callback in SHUTDOWN_CALLBACKS:
callback()
class Globals(object):
spec = {
@@ -522,6 +528,9 @@ class Globals(object):
self.throttles = LiveList(self.zookeeper, "/throttles",
map_fn=ipaddress.ip_network,
reduce_fn=ipaddress.collapse_addresses)
# close our zk connection when the app shuts down
SHUTDOWN_CALLBACKS.append(self.zookeeper.stop)
else:
self.zookeeper = None
parser = ConfigParser.RawConfigParser()