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

core: frontend: improve logic for checking if backend is online in versionchooser #916

Merged
merged 1 commit into from
Mar 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 71 additions & 19 deletions core/frontend/src/components/version-chooser/VersionChooser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -234,25 +234,77 @@ export default Vue.extend({
this.loadCurrentVersion()
},
methods: {
async checkIfBackendIsOnline() {
this.waiting = true
await back_axios({
method: 'get',
url: '/version-chooser/v1.0/version/current',
timeout: 500,
})
.then(() => {
if (this.waiting) {
// Allow 3 seconds so the user can read the "complete" message
// reload(true) forces the browser to fetch the page again
setTimeout(() => { window.location.reload(true) }, 3000)
}
})
.catch((error) => {
console.log(error)
this.waiting = true
backendIsOnline() {
return new Promise((resolve) => {
back_axios({
method: 'get',
url: '/version-chooser/v1.0/version/current',
timeout: 500,
})
.then(() => {
resolve(true)
})
.catch(() => {
resolve(false)
})
})
},

async waitForBackendToGoOffline() {
let timeout = 0
let interval = 0
return new Promise((resolve, reject) => {
timeout = setTimeout(
() => {
reject(new Error('backend took to long to shutdown!'))
clearInterval(interval)
},
20000,
)
interval = setInterval(() => {
this.backendIsOnline().then((backend_online) => {
if (!backend_online) {
clearTimeout(timeout)
clearInterval(interval)
resolve('backend went offline')
}
})
}, 1000)
})
},

waitForBackendToGoOnline() {
let timeout = 0
let interval = 0
return new Promise((resolve, reject) => {
timeout = setTimeout(
() => {
reject(new Error('backend took to long to come back'))
clearInterval(interval)
},
20000,
)
interval = setInterval(() => {
this.backendIsOnline().then((backend_online) => {
if (backend_online) {
clearTimeout(timeout)
clearInterval(interval)
resolve('backend went online')
}
})
}, 1000)
})
},

async waitForBackendToRestart(reload: boolean) {
this.waiting = true
Copy link
Member

Choose a reason for hiding this comment

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

Just to be sure, there is no need to set waiting to false since the logic here is to reload the page, right ?

Copy link
Member Author

Choose a reason for hiding this comment

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

setting waiting to true shows up the overlay and spinner.

await this.waitForBackendToGoOffline()
await this.waitForBackendToGoOnline()
if (reload) {
window.location.reload()
}
},

runningBeta() {
return VCU.getVersionType(this.current_version) === VersionType.Beta
},
Expand Down Expand Up @@ -401,7 +453,7 @@ export default Vue.extend({
// Force it to true again in case the user tried to close the dialog
this.show_pull_output = true
},
}).then(() => setInterval(this.checkIfBackendIsOnline, 1000))
}).then(() => { this.waitForBackendToRestart(true) })
},
async setVersion(args: string | string[]) {
const fullname: string = Array.isArray(args) ? args[0] : args
Expand All @@ -413,7 +465,7 @@ export default Vue.extend({
repository,
tag,
},
}).finally(() => setInterval(this.checkIfBackendIsOnline, 1000))
}).finally(() => { this.waitForBackendToRestart(true) })
},
async deleteVersion(args: string | string[]) {
const fullname: string = Array.isArray(args) ? args[0] : args
Expand Down