-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Make some fields and inits publicly accessible * Retry failed requests where every partial error is serviceUnavailable * Increase min throttle duration to 6 seconds * Use PID to control throttling * Run swiftlint * Use shouldRateLimit * Rename File * Fix build * Fix build * Try setting deadline and tweak PID * Reimplement min/max throttle durations, tweak shouldRateLimit * Don't reset PID when retryAfterSeconds is given * Remove unused variable * Add log, rename variables, use partial errors for retryAfterSeconds * Decrease target success rate and min throttle duration * Fix initial rate limit to 2 * More precision in logs * Rename file and move * Revert "Make some fields and inits publicly accessible" 5de0125 * Upgrade to Swift 5.9 to fix CI * Add back actions/checkout
- Loading branch information
1 parent
5389fb6
commit 94c2d57
Showing
8 changed files
with
146 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"pins" : [ | ||
{ | ||
"identity" : "swift-collections", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-collections.git", | ||
"state" : { | ||
"revision" : "d029d9d39c87bed85b1c50adee7c41795261a192", | ||
"version" : "1.0.6" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-pid", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/ryanashcraft/swift-pid.git", | ||
"state" : { | ||
"revision" : "3f524ecc12bd519f27cbbc73b986be4d60351e91", | ||
"version" : "0.0.3" | ||
} | ||
} | ||
], | ||
"version" : 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
Sources/CloudSyncSession/Extensions/CKErrorExtensions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import CloudKit | ||
|
||
extension CKError { | ||
var suggestedBackoffSeconds: TimeInterval? { | ||
if let retryAfterSeconds { | ||
return retryAfterSeconds | ||
} | ||
|
||
return partialErrorsByItemID? | ||
.values | ||
.compactMap { ($0 as? CKError)?.retryAfterSeconds } | ||
.max() | ||
} | ||
|
||
var indicatesShouldBackoff: Bool { | ||
if retryAfterSeconds != nil { | ||
return true | ||
} | ||
|
||
switch self.code { | ||
case .serviceUnavailable, | ||
.zoneBusy, | ||
.requestRateLimited: | ||
return true | ||
case .partialFailure: | ||
guard let partialErrorsByRecordID = self.partialErrorsByItemID as? [CKRecord.ID: Error] else { | ||
return false | ||
} | ||
|
||
let partialErrors = partialErrorsByRecordID.compactMap { $0.value as? CKError } | ||
let allErrorsAreRetryable = partialErrors.allSatisfy(\.indicatesShouldBackoff) | ||
|
||
return allErrorsAreRetryable | ||
default: | ||
return false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.