From fb9bd5646d8725dc8e0ffeb85c72e27f5c111de6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20S=C3=A1nchez-Gallego?= Date: Wed, 18 Sep 2024 18:13:11 +0000 Subject: [PATCH] Add option to clear lock file before running the action --- src/lvmcryo/__main__.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/lvmcryo/__main__.py b/src/lvmcryo/__main__.py index 79e3cbb..ddfc275 100644 --- a/src/lvmcryo/__main__.py +++ b/src/lvmcryo/__main__.py @@ -141,6 +141,13 @@ async def ln2( show_default=False, ), ] = False, + clear_lock: Annotated[ + bool, + Option( + "--clear-lock", + help="Clears the lock file if it exists before carrying out the action.", + ), + ] = False, # # Purge and fill options # @@ -490,6 +497,10 @@ async def ln2( alerts_route=config.internal_config["api_routes"]["alerts"], ) + if LOCKFILE.exists() and clear_lock: + log.warning("Lock file exists. Removing it because --clear-lock.") + LOCKFILE.unlink() + try: with ensure_lock(LOCKFILE): # Run worker.