From c2a4d8fcd616b87eeed72002aeb5b03554358544 Mon Sep 17 00:00:00 2001 From: Eli Kogan-Wang Date: Tue, 15 Oct 2024 05:18:56 +0200 Subject: [PATCH 1/3] locking error for multiple simultaneous batou deployments is displayed more beautiful --- src/batou/deploy.py | 2 +- src/batou/utils.py | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/batou/deploy.py b/src/batou/deploy.py index c8e62d1c..933cd85d 100644 --- a/src/batou/deploy.py +++ b/src/batou/deploy.py @@ -361,7 +361,7 @@ def main( else: ACTION = "DEPLOYMENT" SUCCESS_FORMAT = {"green": True} - with locked(".batou-lock"): + with locked(".batou-lock", exit_on_failure=True): deployment = Deployment( environment, platform, diff --git a/src/batou/utils.py b/src/batou/utils.py index 7ce3b2b5..93cb107b 100644 --- a/src/batou/utils.py +++ b/src/batou/utils.py @@ -64,13 +64,25 @@ def flush(self): @contextlib.contextmanager -def locked(filename): +def locked(filename, exit_on_failure=False): # XXX can we make this not leave files around? with open(filename, "a+") as lockfile: try: fcntl.lockf(lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB) except IOError: print("Could not acquire lock {}".format(filename), file=sys.stderr) + if exit_on_failure: + print( + "Another instance of batou may be running, or a stale lock file may exist.", + file=sys.stderr, + ) + print( + "If you are sure no other instance is running, you can remove the lock file manually.", + file=sys.stderr, + ) + print("Lock file: {}".format(filename), file=sys.stderr) + print("Exiting.", file=sys.stderr) + sys.exit(1) raise RuntimeError( 'cannot create lock "%s": more than one instance running ' "concurrently?" % lockfile, From 9617fc2dcac3556f7405604b43c18099137d32d8 Mon Sep 17 00:00:00 2001 From: Eli Kogan-Wang Date: Tue, 15 Oct 2024 05:27:28 +0200 Subject: [PATCH 2/3] Add changelog --- CHANGES.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index ad045b0b..3aa78b5e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,9 @@ --------------------- - fix Component.require_one raising a configuration error with strict=False +- The error message shown when a batou deployment fails to start due to another + deployment running at the same time, now correctly informs the user that + another deployment is running instead of showing a traceback. (#446) ## 2.5.0 (2024-09-04) From 6929955c7ae828518082efd31f410fc3ebbcb91a Mon Sep 17 00:00:00 2001 From: Eli Kogan-Wang Date: Tue, 15 Oct 2024 11:40:55 +0200 Subject: [PATCH 3/3] Edit error message for locked files in batou/utils.py --- src/batou/utils.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/batou/utils.py b/src/batou/utils.py index 93cb107b..bf1e6299 100644 --- a/src/batou/utils.py +++ b/src/batou/utils.py @@ -73,14 +73,9 @@ def locked(filename, exit_on_failure=False): print("Could not acquire lock {}".format(filename), file=sys.stderr) if exit_on_failure: print( - "Another instance of batou may be running, or a stale lock file may exist.", + "Another instance of batou is currently running and locked the lockfile.", file=sys.stderr, ) - print( - "If you are sure no other instance is running, you can remove the lock file manually.", - file=sys.stderr, - ) - print("Lock file: {}".format(filename), file=sys.stderr) print("Exiting.", file=sys.stderr) sys.exit(1) raise RuntimeError(