Created
January 27, 2016 09:39
-
-
Save vortec/ac92989051228703e4a5 to your computer and use it in GitHub Desktop.
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
| import time | |
| from threading import Thread | |
| from kazoo.client import KazooState | |
| def create_nodes_after_reconnect(zk): | |
| time.sleep(0.1) | |
| for (service_path, data) in zk.ka_nodes.items(): | |
| register_service(zk, service_path, data, keep_alive=True) | |
| def start_ka_handler(zk): | |
| zk.ka_nodes = {} | |
| def connection_handler(zk_state): | |
| if getattr(zk, 'ka_handler_started', False): | |
| if zk_state == KazooState.CONNECTED: | |
| Thread(target=create_nodes_after_reconnect, args=(zk,)).start() | |
| else: | |
| setattr(zk, 'ka_handler_started', True) | |
| zk.add_listener(connection_handler) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment