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
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
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,
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.',