Skip to content

Commit

Permalink
fix(Controller): Remember strategy when scheduling sync after lock error
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Klehr <[email protected]>
  • Loading branch information
marcelklehr committed Jan 2, 2024
1 parent 6782db6 commit ceb3380
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/lib/Account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
9 changes: 6 additions & 3 deletions src/lib/browser/BrowserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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() {
Expand Down
10 changes: 8 additions & 2 deletions src/lib/native/NativeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,26 @@ 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
}

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) {
Expand Down

0 comments on commit ceb3380

Please sign in to comment.