Use a predictable file path for the lock file.
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -2,24 +2,30 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from django.core.files import locks
|
from django.core.files import locks
|
||||||
|
|
||||||
from common.utils import mkstemp
|
from common.settings import setting_temporary_directory
|
||||||
|
|
||||||
from ..exceptions import LockError
|
from ..exceptions import LockError
|
||||||
|
|
||||||
lock = threading.Lock()
|
lock = threading.Lock()
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
temporary_file = mkstemp()[1]
|
lock_file = os.path.join(
|
||||||
logger.debug('temporary_file: %s', temporary_file)
|
setting_temporary_directory.value, 'mayan_locks.tmp'
|
||||||
|
)
|
||||||
|
open(lock_file, 'a').close()
|
||||||
|
logger.debug('lock_file: %s', lock_file)
|
||||||
|
|
||||||
|
|
||||||
class FileLock(object):
|
class FileLock(object):
|
||||||
|
lock_file = lock_file
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def acquire_lock(cls, name, timeout=None):
|
def acquire_lock(cls, name, timeout=None):
|
||||||
instance = FileLock(name=name, timeout=timeout)
|
instance = FileLock(name=name, timeout=timeout)
|
||||||
@@ -45,7 +51,7 @@ class FileLock(object):
|
|||||||
self.uuid = uuid.uuid4().get_hex()
|
self.uuid = uuid.uuid4().get_hex()
|
||||||
|
|
||||||
lock.acquire()
|
lock.acquire()
|
||||||
with open(temporary_file, 'r+') as file_object:
|
with open(self.__class__.lock_file, 'r+') as file_object:
|
||||||
locks.lock(f=file_object, flags=locks.LOCK_EX)
|
locks.lock(f=file_object, flags=locks.LOCK_EX)
|
||||||
|
|
||||||
data = file_object.read()
|
data = file_object.read()
|
||||||
@@ -73,7 +79,7 @@ class FileLock(object):
|
|||||||
|
|
||||||
def release(self):
|
def release(self):
|
||||||
lock.acquire()
|
lock.acquire()
|
||||||
with open(temporary_file, 'r+') as file_object:
|
with open(self.__class__.lock_file, 'r+') as file_object:
|
||||||
locks.lock(f=file_object, flags=locks.LOCK_EX)
|
locks.lock(f=file_object, flags=locks.LOCK_EX)
|
||||||
try:
|
try:
|
||||||
file_locks = json.loads(file_object.read())
|
file_locks = json.loads(file_object.read())
|
||||||
|
|||||||
Reference in New Issue
Block a user