Browse Source

Merge pull request #1222 from gre/fix/1181

Fixes #1181
master
Meriadec Pillet 7 years ago
committed by GitHub
parent
commit
6736ed327e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      src/bridge/BridgeSyncContext.js
  2. 4
      src/config/constants.js

12
src/bridge/BridgeSyncContext.js

@ -15,7 +15,7 @@ import { updateAccountWithUpdater } from 'actions/accounts'
import { setAccountSyncState } from 'actions/bridgeSync'
import { bridgeSyncSelector, syncStateLocalSelector } from 'reducers/bridgeSync'
import type { BridgeSyncState } from 'reducers/bridgeSync'
import { accountsSelector } from 'reducers/accounts'
import { accountsSelector, isUpToDateSelector } from 'reducers/accounts'
import { SYNC_MAX_CONCURRENT, SYNC_TIMEOUT } from 'config/constants'
import { getBridgeForCurrency } from '.'
@ -26,6 +26,7 @@ type BridgeSyncProviderProps = {
type BridgeSyncProviderOwnProps = BridgeSyncProviderProps & {
bridgeSync: BridgeSyncState,
accounts: Account[],
isUpToDate: boolean,
updateAccountWithUpdater: (string, (Account) => Account) => void,
setAccountSyncState: (string, AsyncState) => *,
}
@ -49,6 +50,7 @@ const BridgeSyncContext = React.createContext((_: BehaviorAction) => {})
const mapStateToProps = createStructuredSelector({
accounts: accountsSelector,
bridgeSync: bridgeSyncSelector,
isUpToDate: isUpToDateSelector,
})
const actions = {
@ -103,6 +105,7 @@ class Provider extends Component<BridgeSyncProviderOwnProps, Sync> {
// by convention we remove concurrent tasks with same priority
// FIXME this is somehow a hack. ideally we should just dedup the account ids in the pending queue...
syncQueue.remove(o => priority === o.priority)
logger.debug('schedule', { type: 'syncQueue', ids })
syncQueue.push(ids, -priority)
}
@ -120,6 +123,10 @@ class Provider extends Component<BridgeSyncProviderOwnProps, Sync> {
if (priority === skipUnderPriority) return
skipUnderPriority = priority
syncQueue.remove(({ priority }) => priority < skipUnderPriority)
if (priority === -1 && !this.props.isUpToDate) {
// going back to -1 priority => retriggering a background sync if it is "Paused"
schedule(shuffledAccountIds(), -1)
}
},
SYNC_ALL_ACCOUNTS: ({ priority }) => {
@ -138,10 +145,11 @@ class Provider extends Component<BridgeSyncProviderOwnProps, Sync> {
const sync = (action: BehaviorAction) => {
const handler = handlers[action.type]
if (handler) {
logger.debug(`action ${action.type}`, { action, type: 'syncQueue' })
// $FlowFixMe
handler(action)
} else {
logger.warn('BridgeSyncContext unsupported action', action)
logger.warn('BridgeSyncContext unsupported action', { action, type: 'syncQueue' })
}
}

4
src/config/constants.js

@ -32,7 +32,9 @@ export const GENUINE_TIMEOUT = intFromEnv('GENUINE_TIMEOUT', 120 * 1000)
export const GET_CALLS_RETRY = intFromEnv('GET_CALLS_RETRY', 2)
export const GET_CALLS_TIMEOUT = intFromEnv('GET_CALLS_TIMEOUT', 30 * 1000)
export const LISTEN_DEVICES_POLLING_INTERVAL = intFromEnv('LISTEN_DEVICES_POLLING_INTERVAL', 1000)
export const OUTDATED_CONSIDERED_DELAY = intFromEnv('OUTDATED_CONSIDERED_DELAY', 5 * 60 * 1000)
// NB: technically speaking OUTDATED_CONSIDERED_DELAY should be set to ZERO.
// but we'll only do that when we're sure the sync is performant and all is working smoothly
export const OUTDATED_CONSIDERED_DELAY = intFromEnv('OUTDATED_CONSIDERED_DELAY', 2 * 60 * 1000)
export const SYNC_ALL_INTERVAL = 120 * 1000
export const SYNC_BOOT_DELAY = 2 * 1000
export const SYNC_PENDING_INTERVAL = 10 * 1000

Loading…
Cancel
Save