Don't enqueue full syncs when going offline
Currently when gertty goes offline, it enqueues a task to sync all subscribed projects and upload all pending reviews. The intent was to make sure gertty resynced quickly in case of an error. However, because the project syncs were at a different priority than the initial project syncs, they could interfere with each other. If a user started gertty after a period of disuse, the initial normal priority sync could take a long time. If it encountered errors that took it offline, it would enqueue a high priority project sync, which would then attempt to sync many of the changes which had already been synced by the normal priority sync (which had not finished and so had not updated the timestamp for the project). Further, this process could repeat if multiple network errors occured. Even further, if the network was flapping, the queue could build up many project sync and upload review tasks themselves. The project sync on reconnect should not actually be necessary because the periodic sync will take care of it, so it is removed in this change. The upload changes on reconnect similarly should not be necessary, but it remains in this change out of an abundance of caution. In case an error disrupts a review upload task in such a way that it is removed from the queue, this should increase the chance it is still uploaded. However, no more than one upload reviews task will appear in the queue, so it should not grow without bound in the case of repeated network errors. Change-Id: Ia0be38625da363055b0451ff2ed80fed16281cda
This commit is contained in:
parent
b16a60d383
commit
86574f5eec
@ -84,6 +84,17 @@ class MultiQueue(object):
|
||||
finally:
|
||||
self.condition.release()
|
||||
|
||||
def has(self, item):
|
||||
self.condition.acquire()
|
||||
try:
|
||||
for queue in self.queues.values():
|
||||
for qitem in queue:
|
||||
if isinstance(qitem, item):
|
||||
return True
|
||||
finally:
|
||||
self.condition.release()
|
||||
return False
|
||||
|
||||
class UpdateEvent(object):
|
||||
def updateRelatedChanges(self, session, change):
|
||||
related_change_keys = set()
|
||||
@ -1044,8 +1055,8 @@ class Sync(object):
|
||||
except requests.ConnectionError, e:
|
||||
self.log.warning("Offline due to: %s" % (e,))
|
||||
if not self.offline:
|
||||
self.submitTask(SyncSubscribedProjectsTask(HIGH_PRIORITY))
|
||||
self.submitTask(UploadReviewsTask(HIGH_PRIORITY))
|
||||
if not self.queue.has(UploadReviewsTask):
|
||||
self.submitTask(UploadReviewsTask(HIGH_PRIORITY))
|
||||
self.offline = True
|
||||
self.app.status.update(offline=True, refresh=False)
|
||||
os.write(pipe, 'refresh\n')
|
||||
|
Loading…
x
Reference in New Issue
Block a user