Skip to content

Commit

Permalink
Merge pull request #43 from klasy/klasys_zkfarmer
Browse files Browse the repository at this point in the history
Fixed zkfarmer to recognize session CLOSED
  • Loading branch information
rs committed Aug 23, 2018
2 parents 860d0c9 + fe23646 commit e2c749f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions zkfarmer/watcher.py
Expand Up @@ -19,7 +19,7 @@


from .utils import serialize, unserialize, ip from .utils import serialize, unserialize, ip
from kazoo.exceptions import NoNodeError, NodeExistsError, ZookeeperError from kazoo.exceptions import NoNodeError, NodeExistsError, ZookeeperError
from kazoo.client import KazooState, OPEN_ACL_UNSAFE from kazoo.client import KazooState, KeeperState, OPEN_ACL_UNSAFE


class ZkFarmWatcher(object): class ZkFarmWatcher(object):


Expand Down Expand Up @@ -95,7 +95,7 @@ def loop(self, count=None, timeout=10, ignore_unknown_transitions=False):
if execute(*args) is False: if execute(*args) is False:
do = False do = False
errors = 0 errors = 0
except ZookeeperError, e: except ZookeeperError as e:
logger.exception("Got a zookeeper exception, reschedule the transition") logger.exception("Got a zookeeper exception, reschedule the transition")
self.events.put((priority, event, args)) self.events.put((priority, event, args))
do = False do = False
Expand Down Expand Up @@ -343,3 +343,11 @@ def exec_znode_modified_from_idle(self):
self.updated_handler() self.updated_handler()
except NoNodeError: except NoNodeError:
logger.warn("not able to watch for node %s: not exist anymore" % self.node_path) logger.warn("not able to watch for node %s: not exist anymore" % self.node_path)

def exec_connection_lost(self):
"""The connection might be closed here"""
logger.debug("We have the client (session) state of " + self.zkconn.client_state)
if self.zkconn.client_state == KeeperState.CLOSED:
logger.error("Zookeeper connection has been dropped since the session is closed and maximum number of retries reached")
self.zkconn.stop()
exit(1)

0 comments on commit e2c749f

Please sign in to comment.