diff --git a/kolibri/core/device/models.py b/kolibri/core/device/models.py index 7e217fa6e94..88d32c1508f 100644 --- a/kolibri/core/device/models.py +++ b/kolibri/core/device/models.py @@ -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 @@ -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")