Added aditional loggin to the locking app
This commit is contained in:
@@ -14,11 +14,11 @@ logger = logging.getLogger(__name__)
|
|||||||
class LockManager(models.Manager):
|
class LockManager(models.Manager):
|
||||||
@transaction.commit_on_success
|
@transaction.commit_on_success
|
||||||
def acquire_lock(self, name, timeout=None):
|
def acquire_lock(self, name, timeout=None):
|
||||||
logger.debug('DEBUG: trying to acquire lock: %s' % name)
|
logger.debug('trying to acquire lock: %s' % name)
|
||||||
lock = self.model(name=name, timeout=timeout)
|
lock = self.model(name=name, timeout=timeout)
|
||||||
try:
|
try:
|
||||||
lock.save(force_insert=True)
|
lock.save(force_insert=True)
|
||||||
logger.debug('DEBUG: acquired lock: %s' % name)
|
logger.debug('acquired lock: %s' % name)
|
||||||
return lock
|
return lock
|
||||||
except IntegrityError:
|
except IntegrityError:
|
||||||
# There is already an existing lock
|
# There is already an existing lock
|
||||||
@@ -27,14 +27,15 @@ class LockManager(models.Manager):
|
|||||||
lock = self.model.objects.get(name=name)
|
lock = self.model.objects.get(name=name)
|
||||||
except self.model.DoesNotExist:
|
except self.model.DoesNotExist:
|
||||||
# Table based locking
|
# Table based locking
|
||||||
logger.debug('DEBUG: lock: %s does not exist' % name)
|
logger.debug('lock: %s does not exist' % name)
|
||||||
raise LockError('Unable to acquire lock')
|
raise LockError('Unable to acquire lock')
|
||||||
|
|
||||||
if datetime.datetime.now() > lock.creation_datetime + datetime.timedelta(seconds=lock.timeout):
|
if datetime.datetime.now() > lock.creation_datetime + datetime.timedelta(seconds=lock.timeout):
|
||||||
logger.debug('DEBUG: reseting deleting stale lock: %s' % name)
|
logger.debug('reseting deleting stale lock: %s' % name)
|
||||||
lock.timeout=timeout
|
lock.timeout=timeout
|
||||||
logger.debug('DEBUG: try to reacquire stale lock: %s' % name)
|
logger.debug('try to reacquire stale lock: %s' % name)
|
||||||
lock.save()
|
lock.save()
|
||||||
return lock
|
return lock
|
||||||
else:
|
else:
|
||||||
|
logger.debug('unable to acquire lock: %s' % name)
|
||||||
raise LockError('Unable to acquire lock')
|
raise LockError('Unable to acquire lock')
|
||||||
|
|||||||
Reference in New Issue
Block a user