Skip to content

Commit

Permalink
Merge pull request #476 from flyingcircusio/446-better-error-if-batou…
Browse files Browse the repository at this point in the history
…-already-running

Better error message if batou deployment is already runnning
  • Loading branch information
zagy authored Oct 15, 2024
2 parents 6964b1c + 0404e1d commit 1e0d7a2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
- fix Component.require_one raising a configuration error with strict=False
- Adds command `./batou secrets decrypttostdout` to decrypt a secrets file to stdout.
- Useful for integration with git diff using textconv, see documentation for installation instructions.
- 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)
Expand Down
2 changes: 1 addition & 1 deletion src/batou/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 8 additions & 1 deletion src/batou/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,20 @@ 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 is currently running and locked the lockfile.",
file=sys.stderr,
)
print("Exiting.", file=sys.stderr)
sys.exit(1)
raise RuntimeError(
'cannot create lock "%s": more than one instance running '
"concurrently?" % lockfile,
Expand Down

0 comments on commit 1e0d7a2

Please sign in to comment.