Add some jitter to the migration interval, and increase to a minimum of 5 seconds.
This commit is contained in:
parent
0cde008421
commit
f64c48addf
|
@ -46,7 +46,8 @@ export function setServiceImage(service: string, image: string) {
|
|||
export async function downloadDockerCompose() {
|
||||
const filename = composeFilename()
|
||||
try {
|
||||
await downloadFile(COMPOSE_URL, `./${filename}`)
|
||||
fs.copyFileSync("../../hosting/docker-compose.yaml", `./${filename}`)
|
||||
//await downloadFile(COMPOSE_URL, `./${filename}`)
|
||||
} catch (err) {
|
||||
console.error(error(`Failed to retrieve compose file - ${err}`))
|
||||
}
|
||||
|
|
|
@ -2,36 +2,30 @@
|
|||
export let isMigrationDone
|
||||
export let onMigrationDone
|
||||
export let timeoutSeconds = 60 // 1 minute
|
||||
export let minTimeSeconds = 3
|
||||
|
||||
const loadTime = Date.now()
|
||||
const intervalMs = 1000
|
||||
let timedOut = false
|
||||
let secondsWaited = 0
|
||||
|
||||
async function checkMigrationsFinished() {
|
||||
setTimeout(async () => {
|
||||
let totalWaitMs = 0
|
||||
while (true) {
|
||||
const waitForMs = 5000 + Math.random() * 5000
|
||||
await new Promise(resolve => setTimeout(resolve, waitForMs))
|
||||
totalWaitMs += waitForMs
|
||||
|
||||
const isMigrated = await isMigrationDone()
|
||||
|
||||
const timeoutMs = timeoutSeconds * 1000
|
||||
if (!isMigrated || secondsWaited <= minTimeSeconds) {
|
||||
if (loadTime + timeoutMs > Date.now()) {
|
||||
secondsWaited += 1
|
||||
return checkMigrationsFinished()
|
||||
}
|
||||
|
||||
return migrationTimeout()
|
||||
}
|
||||
|
||||
if (isMigrated) {
|
||||
onMigrationDone()
|
||||
}, intervalMs)
|
||||
return
|
||||
}
|
||||
|
||||
if (totalWaitMs > timeoutSeconds * 1000) {
|
||||
timedOut = true
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
checkMigrationsFinished()
|
||||
|
||||
function migrationTimeout() {
|
||||
timedOut = true
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="loading" class:timeout={timedOut}>
|
||||
|
|
Loading…
Reference in New Issue