[client-sync] Sync accounts when app comes back online

Summary:
Given that we backoff exponentially in the sync loop when we encounter
RetryableErrors (e.g. network errors), if the app goes offline and
reaches the maximum retry backoff of 5 minutes, and if then the app comes
back online, in the worst case, the sync loop will idle for 5 minutes before trying to
sync, which is undesireable.

To mitigate this, everytime we come online we can wake all of the sync
workers. This shouldn't have any adverse effects

Test Plan: manual

Reviewers: evan, mark, spang

Reviewed By: spang

Differential Revision: https://phab.nylas.com/D4097
This commit is contained in:
Juan Tejada 2017-03-05 23:28:20 -08:00
parent c0510f6015
commit 8bd686bc6e

View file

@ -1,7 +1,7 @@
const _ = require('underscore')
const fs = require('fs')
const {remote} = require('electron')
const {Actions} = require('nylas-exports')
const {Actions, OnlineStatusStore} = require('nylas-exports')
const SyncWorker = require('./sync-worker');
const LocalDatabaseConnector = require('../shared/local-database-connector')
@ -9,15 +9,24 @@ const LocalDatabaseConnector = require('../shared/local-database-connector')
class SyncProcessManager {
constructor() {
this._workers = {};
this._exiting = false;
this._accounts = []
this._exiting = false;
this._resettingEmailCache = false
Actions.wakeLocalSyncWorkerForAccount.listen((accountId) =>
this.wakeWorkerForAccount(accountId, {interrupt: true})
);
this._resettingEmailCache = false
Actions.resetEmailCache.listen(this._resetEmailCache, this)
Actions.debugSync.listen(this._onDebugSync)
Actions.debugSync.listen(this._onDebugSync, this)
OnlineStatusStore.listen(this._onOnlineStatusChanged, this)
}
_onOnlineStatusChanged() {
if (OnlineStatusStore.isOnline()) {
this._accounts.forEach(({id}) => {
this.wakeWorkerForAccount(id, {reason: 'Came back online'})
})
}
}
_onDebugSync() {
@ -63,9 +72,17 @@ class SyncProcessManager {
}
}
accounts() { return this._accounts }
workers() { return _.values(this._workers) }
dbs() { return this.workers().map(w => w._db) }
accounts() {
return this._accounts
}
workers() {
return _.values(this._workers)
}
dbs() {
return this.workers().map(w => w._db)
}
wakeWorkerForAccount(accountId, {reason = 'Waking sync', interrupt} = {}) {
const worker = this._workers[accountId]