Close database connection after lock access to keep this high call code from keeping too many open connections
This commit is contained in:
@@ -3,6 +3,7 @@ from __future__ import absolute_import
|
||||
import logging
|
||||
import datetime
|
||||
|
||||
from django.db import close_connection
|
||||
from django.db.utils import IntegrityError
|
||||
from django.db import transaction
|
||||
from django.db import models
|
||||
@@ -43,3 +44,5 @@ class LockManager(models.Manager):
|
||||
else:
|
||||
logger.debug('unable to acquire lock: %s' % name)
|
||||
raise LockError('Unable to acquire lock')
|
||||
finally:
|
||||
close_connection()
|
||||
|
||||
@@ -29,7 +29,6 @@ class Lock(models.Model):
|
||||
|
||||
@transaction.commit_on_success
|
||||
def release(self):
|
||||
close_connection()
|
||||
try:
|
||||
lock = Lock.objects.get(name=self.name, creation_datetime=self.creation_datetime)
|
||||
lock.delete()
|
||||
@@ -38,6 +37,8 @@ class Lock(models.Model):
|
||||
pass
|
||||
except DatabaseError:
|
||||
transaction.rollback()
|
||||
finally:
|
||||
close_connection()
|
||||
|
||||
class Meta:
|
||||
verbose_name = _(u'lock')
|
||||
|
||||
Reference in New Issue
Block a user