This repository has been archived by the owner on Dec 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
implement sync timeout #1045
Merged
Merged
implement sync timeout #1045
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a90dcc6
implement sync timeout
sashei f6aba6d
add sentry + checking around timeout
sashei f5fffa1
Merge branch 'master' into 1025-sync-timeout
sashei 8667dcc
include sync timed out message
sashei 9f2e5cd
use constant for timeout
sashei 3dcfea7
Merge branch 'master' into 1025-sync-timeout
sashei 8f892b7
fix spec
sashei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -24,14 +24,16 @@ enum SyncError: Error { | |
} | ||
|
||
enum SyncState: Equatable { | ||
case Syncing, Synced | ||
case Syncing, Synced, TimedOut | ||
|
||
public static func ==(lhs: SyncState, rhs: SyncState) -> Bool { | ||
switch (lhs, rhs) { | ||
case (Syncing, Syncing): | ||
return true | ||
case (Synced, Synced): | ||
return true | ||
case (TimedOut, TimedOut): | ||
return true | ||
default: | ||
return false | ||
} | ||
|
@@ -71,7 +73,7 @@ class BaseDataStore { | |
|
||
internal var disposeBag = DisposeBag() | ||
private var listSubject = BehaviorRelay<[LoginRecord]>(value: []) | ||
private var syncSubject = ReplaySubject<SyncState>.create(bufferSize: 1) | ||
private var syncSubject = BehaviorRelay<SyncState>(value: .Synced) | ||
private var storageStateSubject = ReplaySubject<LoginStoreState>.create(bufferSize: 1) | ||
|
||
private let dispatcher: Dispatcher | ||
|
@@ -229,21 +231,29 @@ extension BaseDataStore { | |
else { return } | ||
|
||
if (networkStore.isConnectedToNetwork) { | ||
self.syncSubject.onNext(SyncState.Syncing) | ||
self.syncSubject.accept(SyncState.Syncing) | ||
} else { | ||
self.syncSubject.onNext(SyncState.Synced) | ||
self.syncSubject.accept(SyncState.Synced) | ||
return | ||
} | ||
|
||
queue.async { | ||
self.queue.asyncAfter(deadline: .now() + 20, execute: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this queues for 20 seconds from Also, is it worth making There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, it queues for 20 seconds from now. Constant is a good idea! |
||
// this block serves to "cancel" the sync if the operation is running slowly | ||
if (self.syncSubject.value != .Synced) { | ||
self.syncSubject.accept(.TimedOut) | ||
self.dispatcher.dispatch(action: SentryAction(title: "Sync timeout without error", error: nil, function: "", line: "")) | ||
} | ||
}) | ||
|
||
do { | ||
try self.loginsStorage?.sync(unlockInfo: syncInfo) | ||
} catch let error as LoginStoreError { | ||
self.storageStateSubject.onNext(.Errored(cause: error)) | ||
} catch let error { | ||
NSLog("Unknown error syncing: \(error)") | ||
} | ||
self.syncSubject.onNext(SyncState.Synced) | ||
self.syncSubject.accept(SyncState.Synced) | ||
} | ||
} | ||
|
||
|
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there anyone we need to inform of new/changed localized strings?