diff --git a/src/lib/Account.ts b/src/lib/Account.ts index 005ce39274..5cd3b4cc82 100644 --- a/src/lib/Account.ts +++ b/src/lib/Account.ts @@ -170,7 +170,7 @@ export default class Account { } catch (e) { // Resource locked if (e.code === 37) { - await this.setData({ ...this.getData(), error: null, syncing: false, scheduled: true }) + await this.setData({ ...this.getData(), error: null, syncing: false, scheduled: strategy || this.getData().strategy }) this.syncing = false Logger.log( 'Resource is locked, trying again soon' diff --git a/src/lib/browser/BrowserController.js b/src/lib/browser/BrowserController.js index 7f31ded893..b0b119eaf5 100644 --- a/src/lib/browser/BrowserController.js +++ b/src/lib/browser/BrowserController.js @@ -238,7 +238,6 @@ export default class BrowserController { } async scheduleSync(accountId, wait) { - console.log('called scheduleSync') if (wait) { if (this.schedule[accountId]) { clearTimeout(this.schedule[accountId]) @@ -266,11 +265,15 @@ export default class BrowserController { const status = await this.getStatus() if (status === STATUS_SYNCING) { - await account.setData({ ...account.getData(), scheduled: true }) + await account.setData({ ...account.getData(), scheduled: account.getData().scheduled || true }) return } - await this.syncAccount(accountId) + if (account.getData().scheduled === true) { + await this.syncAccount(accountId) + } else { + await this.syncAccount(accountId, account.getData().scheduled) + } } async scheduleAll() { diff --git a/src/lib/native/NativeController.js b/src/lib/native/NativeController.js index a94ee84eaf..1efa8d5817 100644 --- a/src/lib/native/NativeController.js +++ b/src/lib/native/NativeController.js @@ -111,8 +111,10 @@ export default class NativeController { let account = await Account.get(accountId) if (account.getData().syncing) { + console.log('Account is already syncing. Not syncing again.') return } + // if the account is already scheduled, don't prevent it, to avoid getting stuck if (!account.getData().enabled && !account.getData().scheduled) { console.log('Account is not enabled. Not syncing.') return @@ -120,11 +122,15 @@ export default class NativeController { const status = await this.getStatus() if (status === STATUS_SYNCING) { - await account.setData({ ...account.getData(), scheduled: true }) + await account.setData({ ...account.getData(), scheduled: account.getData().scheduled || true }) return } - this.syncAccount(accountId) + if (account.getData().scheduled === true) { + await this.syncAccount(accountId) + } else { + await this.syncAccount(accountId, account.getData().scheduled) + } } async cancelSync(accountId, keepEnabled) {