feat: add retries when failed to fetch radio candidate

Part-of: <https://dev.funkwhale.audio/funkwhale/funkwhale/-/merge_requests/2330>
This commit is contained in:
Kasper Seweryn 2023-01-20 22:24:19 +01:00 committed by Marge
parent c465b3922d
commit e66426dd4b
1 changed files with 13 additions and 2 deletions

View File

@ -14,6 +14,7 @@ export interface State {
current: null | CurrentRadio current: null | CurrentRadio
running: boolean running: boolean
populating: boolean populating: boolean
retries: number
} }
export interface ObjectId { export interface ObjectId {
@ -39,7 +40,8 @@ const store: Module<State, RootState> = {
state: { state: {
current: null, current: null,
running: false, running: false,
populating: false populating: false,
retries: 0
}, },
getters: { getters: {
types: () => { types: () => {
@ -80,6 +82,7 @@ const store: Module<State, RootState> = {
state.running = false state.running = false
state.current = null state.current = null
state.populating = false state.populating = false
state.retries = 0
}, },
current: (state, value) => { current: (state, value) => {
state.current = value state.current = value
@ -121,7 +124,7 @@ const store: Module<State, RootState> = {
commit('current', null) commit('current', null)
commit('running', false) commit('running', false)
}, },
async populateQueue ({ commit, state }, playNow) { async populateQueue ({ commit, dispatch, state }, playNow) {
if (!state.running || state.populating) { if (!state.running || state.populating) {
return return
} }
@ -140,6 +143,8 @@ const store: Module<State, RootState> = {
? await CLIENT_RADIOS[state.current.type].fetchNextTrack(state.current) ? await CLIENT_RADIOS[state.current.type].fetchNextTrack(state.current)
: await axios.post('radios/tracks/', params).then(response => response.data.track as Track) : await axios.post('radios/tracks/', params).then(response => response.data.track as Track)
state.retries = 0
if (track === undefined) { if (track === undefined) {
isPlaying.value = false isPlaying.value = false
return return
@ -158,8 +163,14 @@ const store: Module<State, RootState> = {
}, { root: true }) }, { root: true })
} else { } else {
logger.error('Error while adding track to queue from radio', error) logger.error('Error while adding track to queue from radio', error)
if (state.retries++ < 5) {
logger.info(`Retrying (${state.retries})...`)
return dispatch('populateQueue', playNow)
}
} }
logger.info('Resetting radio queue due to error or lack of new candidates')
commit('reset') commit('reset')
} finally { } finally {
state.populating = false state.populating = false