Skip to content

Commit 9723146

Browse files
Merge pull request #2421 from laws-africa/activity-deadlock
try to avoid deadlock
2 parents 0d49ae8 + 8d638e8 commit 9723146

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

indigo_api/models/documents.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,6 @@ def is_asleep(self):
815815
return (timezone.now() - self.updated_at).total_seconds() > self.ASLEEP_SECS
816816

817817
@classmethod
818-
def vacuum(cls, document):
818+
def vacuum(cls):
819819
threshold = timezone.now() - datetime.timedelta(seconds=cls.DEAD_SECS)
820-
cls.objects.filter(document=document, updated_at__lte=threshold).delete()
820+
cls.objects.filter(updated_at__lte=threshold).delete()

indigo_api/tasks.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from django.db.utils import OperationalError
1313
from django.dispatch import receiver
1414

15-
from indigo_api.models import Document
15+
from indigo_api.models import Document, DocumentActivity
1616

1717
# get specific task logger
1818
log = logging.getLogger('indigo.tasks')
@@ -88,9 +88,23 @@ def prune_document_versions():
8888
raise e
8989

9090

91+
@background(queue="indigo", remove_existing_tasks=True)
92+
def prune_document_activity():
93+
""" Prune out old DocumentActivity entries.
94+
"""
95+
try:
96+
DocumentActivity.vacuum()
97+
except Exception as e:
98+
log.error(f"Error pruning document activity: {e}", exc_info=e)
99+
raise e
100+
101+
91102
def setup_pruning():
92103
# schedule task to run in 12 hours time, and repeat daily
93-
prune_deleted_documents(schedule=timedelta(hours=12), repeat=Task.DAILY)
104+
prune_deleted_documents(schedule=timedelta(hours=11), repeat=Task.DAILY)
94105

95106
# schedule task to run in 12 hours time, and repeat daily
96107
prune_document_versions(schedule=timedelta(hours=12), repeat=Task.DAILY)
108+
109+
# schedule task to run in 12 hours time, and repeat daily
110+
prune_document_activity(schedule=timedelta(hours=13), repeat=Task.DAILY)

indigo_api/views/documents.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,6 @@ class DocumentActivityViewSet(DocumentResourceView,
286286
def get_queryset(self):
287287
return self.document.activities.prefetch_related('user').all()
288288

289-
def list(self, request, *args, **kwargs):
290-
# clean up old activity
291-
DocumentActivity.vacuum(self.document)
292-
return super(DocumentActivityViewSet, self).list(request, *args, **kwargs)
293-
294289
def create(self, request, *args, **kwargs):
295290
# if they've provided additional finished nonces, clear those out
296291
if request.data.get('finished_nonces'):

0 commit comments

Comments
 (0)