Skip to content

Commit

Permalink
Reduce the chance of database locks interrupting soud syncing.
Browse files Browse the repository at this point in the history
  • Loading branch information
rtibbles committed Feb 15, 2024
1 parent 96755ec commit 31149a3
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions kolibri/core/device/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from kolibri.core.fields import JSONField
from kolibri.core.public.constants.user_sync_options import STALE_QUEUE_TIME
from kolibri.core.utils.cache import process_cache as cache
from kolibri.core.utils.lock import retry_on_db_lock
from kolibri.core.utils.validators import JSON_Schema_Validator
from kolibri.deployment.default.sqlite_db_names import SYNC_QUEUE
from kolibri.plugins.app.utils import interface
Expand Down Expand Up @@ -433,6 +434,12 @@ def increment_and_backoff_next_attempt(self):
# exponential backoff with min of 30 seconds
self.set_next_attempt(28 + 2 ** self.attempts)

@retry_on_db_lock
# Saving these models seems unusually prone to hitting database locks, so we'll retry
# the save operation if we hit a lock.
def save(self, *args, **kwargs):
return super(SyncQueue, self).save(*args, **kwargs)

class Meta:
unique_together = ("user_id", "instance_id")

Expand Down

0 comments on commit 31149a3

Please sign in to comment.