Releases will now back up to the old data when failed to refresh

This commit is contained in:
Kylart 2018-01-11 12:21:04 +01:00
parent 169afd26a8
commit 7a5ec4f2f4
4 changed files with 47 additions and 30 deletions

View File

@ -4,6 +4,9 @@
v-layout(row, wrap, justify-center, style='margin: 0 1% 0 1%;')
v-flex.time-container(md4, sm4, xs8)
span.update-time Updated {{ lastUpdateTime }}.
v-tooltip(top, v-if='notLoaded')
span.update-time.pl-0(slot='activator') *
span The list was not refreshed due to an error.
v-flex(md4, sm1, hidden-xs-only)
v-flex(md2, sm3, xs10)
v-select.select(
@ -113,6 +116,9 @@
},
fansubList () {
return this.$store.state.releases.fansubs
},
notLoaded () {
return this.$store.state.releases.notLoaded
}
},
methods: {

View File

@ -8,7 +8,7 @@ export default {
const {data, status} = await axios.get('getLatestNyaa', { params: state.params })
if (status === 200) {
commit('set', data)
commit('set', {data})
if (state.autoRefresh === true) dispatch('autoRefresh')
} else if (status === 202) {
@ -26,7 +26,7 @@ export default {
const {data, status} = await axios.get('getLatestNyaa', { params: state.params })
if (status === 200) {
commit('set', data)
commit('set', {data})
if (state.autoRefresh === true) dispatch('autoRefresh')
} else if (status === 202) {
@ -44,13 +44,13 @@ export default {
const {data, status} = await axios.get(`getLatest.json?quality=${state.params.quality}`)
if (status === 200) {
commit('set', data)
commit('set', {data})
if (state.autoRefresh === true) dispatch('autoRefresh')
} else if (status === 202) {
log(`An error occurred while getting the latest releases. Retrying in 45 seconds.`)
commit('setInfoSnackbar', 'Could not get the latest releases. Retrying in 45 seconds.', isRoot)
setTimeout(function () {
setTimeout(() => {
log(`Retrying to get latest releases.`)
dispatch('init').catch(err => { void (err) })
}, 45 * 1000)
@ -62,7 +62,6 @@ export default {
}
}
} catch (e) {
console.error(e)
log(`An error occurred while getting the latest releases. Retrying in 45 seconds.`)
commit('setInfoSnackbar', 'Could not get the latest releases. Retrying in 45 seconds.', isRoot)
setTimeout(() => {
@ -74,39 +73,38 @@ export default {
async refresh ({state, commit, dispatch}) {
log(`Refreshing Releases...`)
const retryLater = (backUp) => {
log(`An error occurred while getting the latest releases. Retrying in 45 seconds.`)
commit('setInfoSnackbar', 'Could not get the latest releases. Retrying in 45 seconds.', isRoot)
backUp.length && commit('set', {old: backUp})
setTimeout(() => {
log(`Retrying to get latest releases.`)
dispatch('refresh').catch(err => { void (err) })
}, 45 * 1000)
}
const backUp = state.releases
commit('empty')
try {
const {data, status} = await axios.get('getLatestNyaa', { params: state.params })
if (status === 200) commit('set', data)
if (status === 200) commit('set', {data})
else if (status === 202) {
log(`An error occurred while getting the latest releases. Retrying in 45 seconds.`)
commit('setInfoSnackbar', 'Could not get the latest releases. Retrying in 45 seconds.', isRoot)
setTimeout(() => {
log(`Retrying to get latest releases.`)
dispatch('refresh').catch(err => { void (err) })
}, 45 * 1000)
retryLater(backUp)
} else if (status === 204) {
const {data, status} = await axios.get(`getLatest.json?quality=${state.params.quality}`)
if (status === 200) commit('set', data)
if (status === 200) commit('set', {data})
else if (status === 202 || status === 204) {
log(`An error occurred while getting the latest releases. Retrying in 45 seconds.`)
commit('setInfoSnackbar', 'Could not get the latest releases. Retrying in 45 seconds.', isRoot)
setTimeout(() => {
log(`Retrying to get latest releases.`)
dispatch('refresh').catch(err => { void (err) })
}, 45 * 1000)
retryLater(backUp)
}
}
} catch (e) {
log(`An error occurred while getting the latest releases. Retrying in 45 seconds.`, e)
commit('setInfoSnackbar', 'Could not get the latest releases. Retrying in 45 seconds.', isRoot)
setTimeout(() => {
log(`Retrying to get latest releases.`)
dispatch('refresh').catch(err => { void (err) })
}, 45 * 1000)
retryLater(backUp)
}
},
async autoRefresh ({dispatch, commit, state}) {
@ -118,7 +116,7 @@ export default {
const {data} = await axios.get('getLatestNyaa', { params: state.params })
if (data.length === 18) {
commit('set', data)
commit('set', {data})
dispatch('autoRefresh')
} else {
commit('setInfoSnackbar', 'Auto refresh releases failed... Attempting again in 30 minutes.', isRoot)

View File

@ -1,11 +1,23 @@
import {log, moment} from '../../utils.js'
export default {
set (state, data) {
state.releases = data
state.updateTime = moment()
set (state, obj) {
const {old, data} = obj
log(`Releases updated.`)
if (!old) {
state.updateTime = moment()
state.notLoaded = false
state.releases = data
log(`Releases updated.`)
} else {
state.notLoaded = true
state.releases = old
log('Releases were not updated and put back to a back up.')
}
},
setParams (state, data) {
state.params = data

View File

@ -5,6 +5,7 @@ export default {
releases: [],
autoRefresh: true,
updateTime: moment(),
notLoaded: false,
params: {
quality: '',
fansub: '',