Add purgelock management command. Closes GitLab issue #221.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2017-06-20 01:55:53 -04:00
parent ea636aac7e
commit 5d13f46548
7 changed files with 49 additions and 3 deletions

View File

@@ -13,6 +13,8 @@ from common.settings import setting_temporary_directory
from ..exceptions import LockError
from .base import LockingBackend
lock = threading.Lock()
logger = logging.getLogger(__name__)
@@ -23,7 +25,7 @@ open(lock_file, 'a').close()
logger.debug('lock_file: %s', lock_file)
class FileLock(object):
class FileLock(LockingBackend):
lock_file = lock_file
@classmethod
@@ -31,6 +33,15 @@ class FileLock(object):
instance = FileLock(name=name, timeout=timeout)
return instance
@classmethod
def purge_locks(cls):
lock.acquire()
with open(cls.lock_file, 'r+') as file_object:
locks.lock(f=file_object, flags=locks.LOCK_EX)
file_object.seek(0)
file_object.truncate()
lock.release()
def _get_lock_dictionary(self):
if self.timeout:
result = {