From: Scott Gasch Date: Sat, 20 Aug 2022 18:20:16 +0000 (-0700) Subject: Clarify/improve docs around leases and lease reacquisition. X-Git-Url: https://wannabe.guru.org/gitweb/?a=commitdiff_plain;h=14b85ac54a96e75f3b407061be958a2d373382c0;p=python_utils.git Clarify/improve docs around leases and lease reacquisition. --- 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.',