mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-02-24 16:14:01 +08:00
[local-sync] Add exponential backoff when retrying syncback tasks
Summary: Instead of re-implementing exponential backoff, throw the retryable error so the sync loop handles it and backs-off Test Plan: manual Reviewers: spang, halla Reviewed By: halla Differential Revision: https://phab.nylas.com/D3914
This commit is contained in:
parent
f409bf8be1
commit
d3f0847f79
2 changed files with 11 additions and 8 deletions
|
@ -406,7 +406,7 @@ class SyncWorker {
|
|||
|
||||
let reason = "Scheduled"
|
||||
if (error != null) {
|
||||
reason = `Sync errored`
|
||||
reason = `Sync errored: ${error.message}`
|
||||
} else if (this._interrupted) {
|
||||
reason = `Sync interrupted and restarted. Interrupt reason: ${reason}`
|
||||
} else if (moreToSync) {
|
||||
|
@ -456,10 +456,7 @@ class SyncWorker {
|
|||
const tasks = yield syncbackTaskRunner.getNewSyncbackTasks()
|
||||
this._shouldIgnoreInboxFlagUpdates = true
|
||||
for (const task of tasks) {
|
||||
const {shouldRetry} = await syncbackTaskRunner.runSyncbackTask(task)
|
||||
if (shouldRetry) {
|
||||
this.syncNow({reason: 'Retrying syncback task', interrupt: true});
|
||||
}
|
||||
await syncbackTaskRunner.runSyncbackTask(task)
|
||||
yield // Yield to allow interruption
|
||||
}
|
||||
this._shouldIgnoreInboxFlagUpdates = false
|
||||
|
|
|
@ -147,7 +147,7 @@ class SyncbackTaskRunner {
|
|||
}
|
||||
const before = new Date();
|
||||
const syncbackRequest = task.syncbackRequestObject();
|
||||
let shouldRetry = false
|
||||
let retryableError = null
|
||||
|
||||
this._logger.log(`🔃 📤 ${task.description()}`, syncbackRequest.props)
|
||||
try {
|
||||
|
@ -183,7 +183,7 @@ class SyncbackTaskRunner {
|
|||
provider: this._account.provider,
|
||||
errorMessage: error.message,
|
||||
})
|
||||
shouldRetry = true
|
||||
retryableError = error
|
||||
syncbackRequest.status = "NEW";
|
||||
this._logger.warn(`🔃 📤 ${task.description()} Failed with retryable error, retrying in next loop (${after.getTime() - before.getTime()}ms)`, {syncbackRequest: syncbackRequest.toJSON(), error})
|
||||
} else {
|
||||
|
@ -196,7 +196,13 @@ class SyncbackTaskRunner {
|
|||
} finally {
|
||||
await syncbackRequest.save();
|
||||
}
|
||||
return {shouldRetry}
|
||||
if (retryableError) {
|
||||
// Throw retryable error to interrupt and restart sync loop
|
||||
// The sync loop will take care of backing off when handling retryable
|
||||
// errors.
|
||||
retryableError.message = `${task.description()} failed with retryable error: ${retryableError.message}`
|
||||
throw retryableError
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue