diff --git a/ch_backup/config.py b/ch_backup/config.py index 20c5b1d4..c1e6a6e2 100644 --- a/ch_backup/config.py +++ b/ch_backup/config.py @@ -230,6 +230,7 @@ def _as_seconds(t: str) -> int: "flock_path": "/tmp/flock.lock", "zk_flock_path": "/tmp/zk_flock.lock", "exitcode": 0, + "lock_timeout": _as_seconds("1 min"), }, } diff --git a/ch_backup/logic/lock_manager.py b/ch_backup/logic/lock_manager.py index c07f584e..712c2463 100644 --- a/ch_backup/logic/lock_manager.py +++ b/ch_backup/logic/lock_manager.py @@ -41,6 +41,7 @@ def __init__(self, lock_conf: dict, zk_ctl: Optional[ZookeeperCTL]) -> None: self._exitcode = lock_conf.get("exitcode") self._distributed = zk_ctl is None self._disabled = False + self._lock_timeout = lock_conf.get("lock_timeout") def __call__(self, distributed: bool = True, disabled: bool = False): # type: ignore """ @@ -106,7 +107,7 @@ def _zk_flock(self) -> None: if not client.exists(self._process_zk_lockfile_path): client.create(self._process_zk_lockfile_path, makepath=True) self._zk_lock = client.Lock(self._process_zk_lockfile_path) - if not self._zk_lock.acquire(blocking=False): + if not self._zk_lock.acquire(blocking=True, timeout=self._lock_timeout): sys.exit(self._exitcode) else: raise RuntimeError("ZK flock enabled, but zookeeper is not configured")