From 071d4c51711f654edefe704174422caea1d13ea7 Mon Sep 17 00:00:00 2001 From: Scott Gasch Date: Fri, 19 Aug 2022 21:47:01 -0700 Subject: [PATCH] Break a dependency from zookeeper to config. --- zookeeper.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) mode change 100755 => 100644 zookeeper.py 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, ): -- 2.47.1