Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added configuration for the max attempt request #3193

Merged
merged 8 commits into from
Jul 10, 2019
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Shipping address is saved as default when not logged in user chooses to create account during checkout - @iwonapiotrowska (#2636)
- Can set transition style for Modal content - @grimasod (#3146)
- Added stock to cart items - @cheeerd (#3166)
- Added configuration for max attempt task & cart by pass - @cnviradiya (#3193)

## [1.10.0-rc.2] - UNRELEASED

Expand Down
4 changes: 4 additions & 0 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@
"initialStateFilter": ["__DEMO_MODE__", "version", "storeView"],
"useInitialStateFilter": true
},
"queues": {
"maxNetworkTaskAttempts": 1,
"maxCartBypassAttempts": 1
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

"defaultStoreCode": "",
"storeViews": {
"multistore": false,
Expand Down
5 changes: 2 additions & 3 deletions core/lib/sync/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { serial } from '@vue-storefront/core/helpers'
import config from 'config'
import { onlineHelper } from '@vue-storefront/core/helpers'

const AUTO_REFRESH_MAX_ATTEMPTS = 20

export function _prepareTask (task) {
const taskId = entities.uniqueEntityId(task) // timestamp as a order id is not the best we can do but it's enough
Expand Down Expand Up @@ -84,7 +83,7 @@ function _internalExecute (resolve, reject, task: Task, currentToken, currentCar
if (config.users.autoRefreshTokens) {
if (!rootStore.state.userTokenInvalidateLock) {
rootStore.state.userTokenInvalidateLock++
if (rootStore.state.userTokenInvalidateAttemptsCount >= AUTO_REFRESH_MAX_ATTEMPTS) {
if (rootStore.state.userTokenInvalidateAttemptsCount >= config.queues.maxNetworkTaskAttempts) {
Logger.error('Internal Application error while refreshing the tokens. Please clear the storage and refresh page.', 'sync')()
rootStore.state.userTokenInvalidateLock = -1
rootStore.dispatch('user/logout', { silent: true })
Expand Down Expand Up @@ -120,7 +119,7 @@ function _internalExecute (resolve, reject, task: Task, currentToken, currentCar
})
}
}
if (rootStore.state.userTokenInvalidateAttemptsCount <= AUTO_REFRESH_MAX_ATTEMPTS) _internalExecute(resolve, reject, task, currentToken, currentCartId) // retry
if (rootStore.state.userTokenInvalidateAttemptsCount <= config.queues.maxNetworkTaskAttempts) _internalExecute(resolve, reject, task, currentToken, currentCartId) // retry
} else {
Logger.info('Invalidation process is disabled (autoRefreshTokens is set to false)', 'sync')()
rootStore.dispatch('user/logout', { silent: true })
Expand Down
5 changes: 2 additions & 3 deletions core/modules/cart/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { isServer } from '@vue-storefront/core/helpers'
import config from 'config'
import Task from '@vue-storefront/core/lib/sync/types/Task'

const MAX_BYPASS_COUNT = 10
let _connectBypassCount = 0

function _getDifflogPrototype () {
Expand Down Expand Up @@ -207,7 +206,7 @@ const actions: ActionTree<CartState, RootState> = {
diffLog = await dispatch('merge', { serverItems: task.result, clientItems: getters.getCartItems, dryRun: dryRun, forceClientState: forceClientState })
} else {
Logger.error(task.result, 'cart') // override with guest cart()
if (_connectBypassCount < MAX_BYPASS_COUNT) {
if (_connectBypassCount < config.queues.maxCartBypassAttempts) {
Logger.log('Bypassing with guest cart' + _connectBypassCount, 'cart')()
_connectBypassCount = _connectBypassCount + 1
await dispatch('connect', { guestCart: true })
Expand Down Expand Up @@ -524,7 +523,7 @@ const actions: ActionTree<CartState, RootState> = {
} else {
let resultString = task.result ? toString(task.result) : null
if (resultString && (resultString.indexOf(i18n.t('not authorized')) < 0 && resultString.indexOf('not authorized')) < 0) { // not respond to unathorized errors here
if (_connectBypassCount < MAX_BYPASS_COUNT) {
if (_connectBypassCount < config.queues.maxCartBypassAttempts) {
Logger.log('Bypassing with guest cart' + _connectBypassCount, 'cart')()
_connectBypassCount = _connectBypassCount + 1
Logger.error(task.result, 'cart')()
Expand Down