1
0
Fork 0
mirror of synced 2024-07-13 02:05:54 +12:00

Add some jitter to the migration interval, and increase to a minimum of 5 seconds.

This commit is contained in:
Sam Rose 2024-06-21 17:09:39 +01:00
parent 0cde008421
commit f64c48addf
No known key found for this signature in database
2 changed files with 16 additions and 21 deletions

View file

@ -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}`))
}

View file

@ -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()
return
}
onMigrationDone()
}, intervalMs)
if (totalWaitMs > timeoutSeconds * 1000) {
timedOut = true
return
}
}
}
checkMigrationsFinished()
function migrationTimeout() {
timedOut = true
}
</script>
<div class="loading" class:timeout={timedOut}>