mirror of
https://github.com/ansible/awx.git
synced 2026-01-11 10:00:01 -03:30
avoid instance record deadlock by using pglock
This commit is contained in:
parent
5ab1a76785
commit
f1b1c4ee97
@ -9,7 +9,6 @@ from sets import Set
|
|||||||
# Django
|
# Django
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import transaction, connection
|
from django.db import transaction, connection
|
||||||
from django.db.utils import DatabaseError
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.utils.timezone import now as tz_now
|
from django.utils.timezone import now as tz_now
|
||||||
|
|
||||||
@ -24,6 +23,8 @@ from awx.main.tasks import _send_notification_templates
|
|||||||
# Celery
|
# Celery
|
||||||
from celery.task.control import inspect
|
from celery.task.control import inspect
|
||||||
|
|
||||||
|
from django_pglocks import advisory_lock
|
||||||
|
|
||||||
logger = logging.getLogger('awx.main.scheduler')
|
logger = logging.getLogger('awx.main.scheduler')
|
||||||
|
|
||||||
|
|
||||||
@ -459,13 +460,12 @@ class TaskManager():
|
|||||||
logger.debug("Starting Schedule")
|
logger.debug("Starting Schedule")
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
# Lock
|
# Lock
|
||||||
try:
|
with advisory_lock('task_manager_lock', wait=False) as acquired:
|
||||||
Instance.objects.select_for_update(nowait=True).all()[0]
|
if acquired is False:
|
||||||
except DatabaseError:
|
return
|
||||||
return
|
|
||||||
|
|
||||||
finished_wfjs = self._schedule()
|
finished_wfjs = self._schedule()
|
||||||
|
|
||||||
# Operations whose queries rely on modifications made during the atomic scheduling session
|
# Operations whose queries rely on modifications made during the atomic scheduling session
|
||||||
for wfj in WorkflowJob.objects.filter(id__in=finished_wfjs):
|
for wfj in WorkflowJob.objects.filter(id__in=finished_wfjs):
|
||||||
_send_notification_templates(wfj, 'succeeded' if wfj.status == 'successful' else 'failed')
|
_send_notification_templates(wfj, 'succeeded' if wfj.status == 'successful' else 'failed')
|
||||||
|
|||||||
3
docs/licenses/django-pglocks.txt
Normal file
3
docs/licenses/django-pglocks.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Copyright (c) 2013 Christophe Pettus
|
||||||
|
|
||||||
|
Licensed under the MIT License.
|
||||||
@ -16,6 +16,7 @@ django-crum==0.7.1
|
|||||||
django-extensions==1.7.8
|
django-extensions==1.7.8
|
||||||
django-jsonfield==1.0.1
|
django-jsonfield==1.0.1
|
||||||
django-polymorphic==1.2
|
django-polymorphic==1.2
|
||||||
|
django-pglocks==1.0.2
|
||||||
django-radius==1.1.0
|
django-radius==1.1.0
|
||||||
django-solo==1.1.2
|
django-solo==1.1.2
|
||||||
django-split-settings==0.2.5
|
django-split-settings==0.2.5
|
||||||
|
|||||||
@ -59,6 +59,7 @@ django-crum==0.7.1
|
|||||||
django-extensions==1.7.8
|
django-extensions==1.7.8
|
||||||
django-jsonfield==1.0.1
|
django-jsonfield==1.0.1
|
||||||
django-polymorphic==1.2
|
django-polymorphic==1.2
|
||||||
|
django-pglocks==1.0.2
|
||||||
django-radius==1.1.0
|
django-radius==1.1.0
|
||||||
django-solo==1.1.2
|
django-solo==1.1.2
|
||||||
django-split-settings==0.2.5
|
django-split-settings==0.2.5
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user