summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Gasch <[email protected]>2022-08-20 11:20:16 -0700
committerScott Gasch <[email protected]>2022-08-20 11:20:16 -0700
commit14b85ac54a96e75f3b407061be958a2d373382c0 (patch)
tree1036c4251cee6c60b353d02827c66b9b97b93563
parente65c692279786d17bce47ebc2ce3c473f7d3bf27 (diff)
Clarify/improve docs around leases and lease reacquisition.
-rw-r--r--zookeeper.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/zookeeper.py b/zookeeper.py
index 9decfef..480ce1a 100644
--- a/zookeeper.py
+++ b/zookeeper.py
@@ -13,7 +13,7 @@ import os
import platform
import sys
import threading
-from typing import Callable, Optional
+from typing import Any, Callable, Optional
from kazoo.client import KazooClient
from kazoo.protocol.states import KazooState
@@ -43,6 +43,16 @@ def obtain_lease(
before invoking a function or skip invoking the function if the
lease cannot be obtained.
+ There is no method of releasing a lease manually provided on
+ the Kazoo public lease API. Therefore, letting the lease expire
+ is the only mechanism by which it becomes re-acquirable at this
+ time. Thus, due consideration is in order when choosing the
+ initial duration.
+
+ According to Kazoo docs, "The client may renew the lease without
+ losing it by obtaining a new lease with the same path (lease_id)
+ and same identity (contender_id)."
+
Args:
lease_id: string identifying the lease to obtain
contender_id: string identifying who's attempting to obtain
@@ -69,7 +79,7 @@ def obtain_lease(
def wrapper(func: Callable) -> Callable:
@functools.wraps(func)
- def wrapper2(*args, **kwargs):
+ def wrapper2(*args, **kwargs) -> Optional[Any]:
zk = KazooClient(
hosts=scott_secrets.ZOOKEEPER_NODES,
use_ssl=True,
@@ -102,6 +112,7 @@ def obtain_lease(
if also_pass_lease:
args = (*args, lease)
ret = func(*args, *kwargs)
+ # Release the lease?
else:
logger.debug(
'Failed to obtain %s for contender %s, doing nothing more.',