From: Scott Gasch Date: Sat, 20 Aug 2022 04:47:01 +0000 (-0700) Subject: Break a dependency from zookeeper to config. X-Git-Url: https://wannabe.guru.org/gitweb/?a=commitdiff_plain;h=071d4c51711f654edefe704174422caea1d13ea7;p=python_utils.git Break a dependency from zookeeper to config. --- diff --git a/zookeeper.py b/zookeeper.py old mode 100755 new mode 100644 index e2e6ce4..f96d414 --- a/zookeeper.py +++ b/zookeeper.py @@ -9,7 +9,9 @@ import datetime import functools import logging +import os import platform +import sys import threading import time from typing import Callable, Optional @@ -17,17 +19,22 @@ from typing import Callable, Optional from kazoo.client import KazooClient from kazoo.protocol.states import KazooState -import config import file_utils import scott_secrets logger = logging.getLogger(__name__) +# On module load, grab what we presume to be our process' program name. +# This is used, by default, as part of internal zookeeper paths (e.g. +# to name a lease or election). +PROGRAM_NAME: str = os.path.basename(sys.argv[0]) + + def obtain_lease( f: Optional[Callable] = None, *, - lease_id: str = config.PROGRAM_NAME, + lease_id: str = PROGRAM_NAME, contender_id: str = platform.node(), initial_duration: datetime.timedelta = datetime.timedelta(minutes=5), also_pass_lease: bool = False, @@ -109,7 +116,7 @@ def obtain_lease( def run_for_election( f: Optional[Callable] = None, *, - election_id: str = config.PROGRAM_NAME, + election_id: str = PROGRAM_NAME, contender_id: str = platform.node(), also_pass_zk_client: bool = False, ):