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
This commit is contained in:
parent
af7ffe0e2a
commit
68d941b5ea
@ -310,6 +310,34 @@ def synchronized_with_prefix(lock_file_prefix):
|
|||||||
return functools.partial(synchronized, lock_file_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):
|
def _lock_wrapper(argv):
|
||||||
"""Create a dir for locks and pass it to command from arguments
|
"""Create a dir for locks and pass it to command from arguments
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user