1
0
Fork 0
mirror of synced 2024-08-05 13:21:26 +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() { export async function downloadDockerCompose() {
const filename = composeFilename() const filename = composeFilename()
try { try {
await downloadFile(COMPOSE_URL, `./${filename}`) fs.copyFileSync("../../hosting/docker-compose.yaml", `./${filename}`)
//await downloadFile(COMPOSE_URL, `./${filename}`)
} catch (err) { } catch (err) {
console.error(error(`Failed to retrieve compose file - ${err}`)) console.error(error(`Failed to retrieve compose file - ${err}`))
} }

View file

@ -2,36 +2,30 @@
export let isMigrationDone export let isMigrationDone
export let onMigrationDone export let onMigrationDone
export let timeoutSeconds = 60 // 1 minute export let timeoutSeconds = 60 // 1 minute
export let minTimeSeconds = 3
const loadTime = Date.now()
const intervalMs = 1000
let timedOut = false let timedOut = false
let secondsWaited = 0
async function checkMigrationsFinished() { 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 isMigrated = await isMigrationDone()
if (isMigrated) {
const timeoutMs = timeoutSeconds * 1000 onMigrationDone()
if (!isMigrated || secondsWaited <= minTimeSeconds) { return
if (loadTime + timeoutMs > Date.now()) {
secondsWaited += 1
return checkMigrationsFinished()
}
return migrationTimeout()
} }
onMigrationDone() if (totalWaitMs > timeoutSeconds * 1000) {
}, intervalMs) timedOut = true
return
}
}
} }
checkMigrationsFinished() checkMigrationsFinished()
function migrationTimeout() {
timedOut = true
}
</script> </script>
<div class="loading" class:timeout={timedOut}> <div class="loading" class:timeout={timedOut}>