Break a dependency from zookeeper to config.
authorScott Gasch <[email protected]>
Sat, 20 Aug 2022 04:47:01 +0000 (21:47 -0700)
committerScott Gasch <[email protected]>
Sat, 20 Aug 2022 04:47:01 +0000 (21:47 -0700)
zookeeper.py [changed mode: 0755->0644]

old mode 100755 (executable)
new mode 100644 (file)
index e2e6ce4..f96d414
@@ -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,
 ):