diff options
author | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2021-10-06 16:13:26 -0400 |
---|---|---|
committer | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2021-10-06 16:13:26 -0400 |
commit | d9cad9011218fb192bd171c4be80688f5b845e4f (patch) | |
tree | 97c668b973043bcab07fd3f8ebae8b8a7266c2e9 | |
parent | f61504244bfe18c3cba18de83c19f51d9ebeae56 (diff) | |
download | korg-helpers-d9cad9011218fb192bd171c4be80688f5b845e4f.tar.gz |
git-patchwork-bot: use a global lock
When running operations that require the shared cache database, make
sure that only a single instance of the bot is running.
Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rwxr-xr-x | git-patchwork-bot.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/git-patchwork-bot.py b/git-patchwork-bot.py index 640f7f2..62a44be 100755 --- a/git-patchwork-bot.py +++ b/git-patchwork-bot.py @@ -1052,13 +1052,6 @@ def pwrun(repo, rsettings): logger.info('Could not get the latest ref in %s', repo) sys.exit(1) - try: - lockfh = open(os.path.join(repo, '.pwrun.lock'), 'w') - lockf(lockfh, LOCK_EX | LOCK_NB) - except IOError: - logger.debug('Could not obtain an exclusive lock, assuming another process is running.') - return - # Do we have a pw.db there yet? dbpath = os.path.join(repo, 'pw.db') db_exists = os.path.isfile(dbpath) @@ -1288,7 +1281,14 @@ def pwrun(repo, rsettings): def check_repos(): - # First, we run all repositories + # Use a global lock to make sure only a single process is running + try: + lockfh = open(os.path.join(CACHEDIR, 'patchwork-bot.global.lock'), 'w') + lockf(lockfh, LOCK_EX | LOCK_NB) + except IOError: + logger.info('Could not obtain an exclusive lock, assuming another process is running.') + sys.exit(0) + for repo in CONFIG['repos']: fullpath = os.path.join(cmdargs.reposdir.rstrip('/'), repo.lstrip('/')) if not os.path.isdir(fullpath): |