mirror of
https://github.com/zhigang1992/devhub.git
synced 2026-06-15 09:58:29 +08:00
Pause fetch retries for 5 minutes after an error occurs
E.g. if a user type the wrong username, previously it was trying to refetch every 10 seconds
This commit is contained in:
@@ -190,8 +190,9 @@ export const subscriptionsReducer: Reducer<State> = (
|
||||
if (!subscription) return
|
||||
|
||||
subscription.data = subscription.data || {}
|
||||
subscription.data.loadState = 'error'
|
||||
subscription.data.errorMessage = action.error && action.error.message
|
||||
subscription.data.lastFetchedAt = new Date().toISOString()
|
||||
subscription.data.loadState = 'error'
|
||||
|
||||
// draft.updatedAt = new Date().toISOString()
|
||||
})
|
||||
|
||||
@@ -76,6 +76,26 @@ function* init() {
|
||||
subscriptionsToFetch.map(function*(subscription) {
|
||||
if (!subscription) return
|
||||
|
||||
const fiveMinutes = 1000 * 60 * 5
|
||||
const timeDiff = subscription.data.lastFetchedAt
|
||||
? Date.now() - new Date(subscription.data.lastFetchedAt).valueOf()
|
||||
: undefined
|
||||
|
||||
if (
|
||||
subscription &&
|
||||
subscription.data &&
|
||||
subscription.data.loadState === 'error' &&
|
||||
(!timeDiff || timeDiff < fiveMinutes)
|
||||
) {
|
||||
if (__DEV__) {
|
||||
// tslint:disable-next-line no-console
|
||||
console.debug(
|
||||
'Ignoring subscription re-fetch due to recent fetch error.',
|
||||
)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
return yield put(
|
||||
actions.fetchSubscriptionRequest({
|
||||
subscriptionId: subscription.id,
|
||||
|
||||
Reference in New Issue
Block a user