mirror of
https://github.com/ansible/awx.git
synced 2026-05-24 00:57:48 -02:30
Handle database errors and retry
This commit is contained in:
@@ -27,7 +27,7 @@ from celery import Task, task
|
||||
|
||||
# Django
|
||||
from django.conf import settings
|
||||
from django.db import transaction
|
||||
from django.db import transaction, DatabaseError
|
||||
from django.utils.datastructures import SortedDict
|
||||
from django.utils.timezone import now
|
||||
|
||||
@@ -87,6 +87,9 @@ class BaseTask(Task):
|
||||
# Commit outstanding transaction so that we fetch the latest object
|
||||
# from the database.
|
||||
transaction.commit()
|
||||
save_succeeded = True
|
||||
while True:
|
||||
try:
|
||||
instance = self.model.objects.get(pk=pk)
|
||||
if updates:
|
||||
update_fields = ['modified']
|
||||
@@ -100,6 +103,13 @@ class BaseTask(Task):
|
||||
update_fields.append('failed')
|
||||
instance.save(update_fields=update_fields)
|
||||
transaction.commit()
|
||||
save_succeeded = True
|
||||
except DatabaseError as e:
|
||||
logger.debug("Database error encountered, retrying: " + str(e))
|
||||
save_succeeded = False
|
||||
finally:
|
||||
if save_succeeded:
|
||||
break
|
||||
return instance
|
||||
|
||||
def get_model(self, pk):
|
||||
|
||||
Reference in New Issue
Block a user