Skip to content

Commit

Permalink
attempt to load channel multiple times if failed
Browse files Browse the repository at this point in the history
  • Loading branch information
liamcottle committed Nov 28, 2024
1 parent ff273b8 commit 0a02ee2
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions src/components/pages/settings/NodeChannelsSettingsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,36 @@ export default {
const channelsToLoad = 8;
for(var channelIndex = 0; channelIndex < channelsToLoad; channelIndex++){
// to fetch the first channel (primary) you must send a channel index of 1
this.loadingStatus = `Fetching Channel ${channelIndex + 1} / ${channelsToLoad}`;
const channel = await NodeAPI.remoteAdminGetChannel(this.nodeId, channelIndex + 1);
// add to channels list
channels.push(channel);
this.channelsLoaded = channels.length;
// we might fail to get some responses, so we will retry a few times
var maxAttempts = 5;
var fetchedChannel = false;
var fetchError = null;
for(var attempt = 0; attempt < maxAttempts; attempt++){
try {
// to fetch the first channel (primary) you must send a channel index of 1
this.loadingStatus = `Fetching Channel ${channelIndex + 1} / ${channelsToLoad}`;
const channel = await NodeAPI.remoteAdminGetChannel(this.nodeId, channelIndex + 1);
// add to channels list
channels.push(channel);
this.channelsLoaded = channels.length;
fetchedChannel = true;
// we got the channel, so no need to attempt to fetch again
break;
} catch(e) {
console.log(e);
fetchError = e;
}
}
// if we didn't fetch the channel, bail out
if(!fetchedChannel){
console.log(`failed to fetch channel after ${maxAttempts} attempts`);
throw fetchError;
}
}
Expand Down

0 comments on commit 0a02ee2

Please sign in to comment.