summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Gasch <[email protected]>2022-08-23 09:59:49 -0700
committerScott Gasch <[email protected]>2022-08-23 09:59:49 -0700
commitf9e0d471e6d57b62cdc21a904ae48a2a43331bec (patch)
tree651be09230f67af9603898a1382dd9ff66a4e681
parent54c53bc3d6844ee31a49a975a54eeb700d872efc (diff)
Improve docs.
-rw-r--r--zookeeper.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/zookeeper.py b/zookeeper.py
index 39730fa..2b50059 100644
--- a/zookeeper.py
+++ b/zookeeper.py
@@ -57,7 +57,6 @@ class RenewableReleasableLease(NonBlockingLease):
expired or released lease by calling renew. Go create a new lease
object at that point. Finally, note that when you renew the lease
it will evaluate to False briefly as it is reobtained.
-
"""
def __init__(
@@ -75,7 +74,12 @@ class RenewableReleasableLease(NonBlockingLease):
self.utcnow = utcnow
def release(self) -> bool:
- """Release the lease, if it's presently being held."""
+ """Release the lease, if it's presently being held.
+
+ Returns:
+ True if the lease was successfully released,
+ False otherwise.
+ """
self.client.ensure_path(self.path)
holder_path = self.path + "/lease_holder"
lock = self.client.Lock(self.path, self.identifier)
@@ -102,6 +106,19 @@ class RenewableReleasableLease(NonBlockingLease):
return False
def try_renew(self, duration: datetime.timedelta) -> bool:
+ """Attempt to renew a lease that is currently held. Note that
+ this will cause self to evaluate to False briefly as the lease
+ is renewed.
+
+ Args:
+ duration: the amount of additional time to add to the
+ current lease expiration.
+
+ Returns:
+ True if the lease was successfully renewed,
+ False otherwise.
+ """
+
if not self.obtained:
return False
self.obtained = False
@@ -124,6 +141,11 @@ class RenewableReleasableLease(NonBlockingLease):
return False
def __bool__(self):
+ """Note that this implementation differs from that of the base
+ class in that it probes zookeeper to ensure that the lease is
+ not yet expired and is therefore more expensive.
+ """
+
if not self.obtained:
return False
lock = self.client.Lock(self.path, self.identifier)