summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2015-11-30 12:13:44 -0800
committerJoshua Harlow <harlowja@yahoo-inc.com>2015-11-30 12:13:44 -0800
commit68d941b5eaf6fbaa444ff89dd81285c94b5cfb83 (patch)
treea8d0956eac638700e7c58f9fcfe33320611703aa
parentaf7ffe0e2af1aed15f6e9300668d952d7955682f (diff)
downloadoslo-concurrency-68d941b5eaf6fbaa444ff89dd81285c94b5cfb83.tar.gz
Add complementary remove lock with prefix function
It seems we provide (and projects use) the provided decorator 'synchronized_with_prefix' but we don't provide an equivalent function to complement that function to clean up its created lock files. Providing a complementary method seems pretty useful for projects that actually clean up these lock files (if any actually do in the first place). Change-Id: I601ce3992411e6a2ddded13aba4ac068cf8f14e2
-rw-r--r--oslo_concurrency/lockutils.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/oslo_concurrency/lockutils.py b/oslo_concurrency/lockutils.py
index 6eb8eb4..2e61ff3 100644
--- a/oslo_concurrency/lockutils.py
+++ b/oslo_concurrency/lockutils.py
@@ -310,6 +310,34 @@ def synchronized_with_prefix(lock_file_prefix):
return functools.partial(synchronized, lock_file_prefix=lock_file_prefix)
+def remove_external_lock_file_with_prefix(lock_file_prefix):
+ """Partial object generator for the remove lock file function.
+
+ Redefine remove_external_lock_file_with_prefix in each project like so::
+
+ (in nova/utils.py)
+ from nova.openstack.common import lockutils
+
+ synchronized = lockutils.synchronized_with_prefix('nova-')
+ synchronized_remove = lockutils.remove_external_lock_file_with_prefix(
+ 'nova-')
+
+ (in nova/foo.py)
+ from nova import utils
+
+ @utils.synchronized('mylock')
+ def bar(self, *args):
+ ...
+
+ <eventually call synchronized_remove('mylock') to cleanup>
+
+ The lock_file_prefix argument is used to provide lock files on disk with a
+ meaningful prefix.
+ """
+ return functools.partial(remove_external_lock_file,
+ lock_file_prefix=lock_file_prefix)
+
+
def _lock_wrapper(argv):
"""Create a dir for locks and pass it to command from arguments