Add ZK session timeout option
Change-Id: If804c18f2103baa12c9c3bd0344a166fac1ea749
This commit is contained in:
parent
499c3046f8
commit
e2f0a87ad8
|
@ -115,6 +115,11 @@ The following sections of ``zuul.conf`` are used by all Zuul components:
|
|||
A list of zookeeper hosts for Zuul to use when communicating
|
||||
with Nodepool.
|
||||
|
||||
.. attr:: session_timeout
|
||||
:default: 10.0
|
||||
|
||||
The ZooKeeper session timeout, in seconds.
|
||||
|
||||
|
||||
.. _scheduler:
|
||||
|
||||
|
|
|
@ -154,8 +154,10 @@ class Scheduler(zuul.cmd.ZuulApp):
|
|||
zookeeper = zuul.zk.ZooKeeper()
|
||||
zookeeper_hosts = get_default(self.config, 'zookeeper',
|
||||
'hosts', '127.0.0.1:2181')
|
||||
zookeeper_timeout = float(get_default(self.config, 'zookeeper',
|
||||
'session_timeout', 10.0))
|
||||
|
||||
zookeeper.connect(zookeeper_hosts)
|
||||
zookeeper.connect(zookeeper_hosts, timeout=zookeeper_timeout)
|
||||
|
||||
cache_expiry = get_default(self.config, 'webapp', 'status_expiry', 1)
|
||||
listen_address = get_default(self.config, 'webapp', 'listen_address',
|
||||
|
|
|
@ -90,7 +90,7 @@ class ZooKeeper(object):
|
|||
def resetLostFlag(self):
|
||||
self._became_lost = False
|
||||
|
||||
def connect(self, hosts, read_only=False):
|
||||
def connect(self, hosts, read_only=False, timeout=10.0):
|
||||
'''
|
||||
Establish a connection with ZooKeeper cluster.
|
||||
|
||||
|
@ -100,10 +100,12 @@ class ZooKeeper(object):
|
|||
:param str hosts: Comma-separated list of hosts to connect to (e.g.
|
||||
127.0.0.1:2181,127.0.0.1:2182,[::1]:2183).
|
||||
:param bool read_only: If True, establishes a read-only connection.
|
||||
|
||||
:param float timeout: The ZooKeeper session timeout, in
|
||||
seconds (default: 10.0).
|
||||
'''
|
||||
if self.client is None:
|
||||
self.client = KazooClient(hosts=hosts, read_only=read_only)
|
||||
self.client = KazooClient(hosts=hosts, read_only=read_only,
|
||||
timeout=timeout)
|
||||
self.client.add_listener(self._connection_listener)
|
||||
self.client.start()
|
||||
|
||||
|
|
Loading…
Reference in New Issue