Skip to content

Commit

Permalink
Ensure app store initialisation retry logic is applied
Browse files Browse the repository at this point in the history
We had retry logic before but it wasn't working because
`AppStore.update()` never throws it silently fails to be safe to run in
a loop without causing exceptions. Now we have custom logic to only pull
the default app repo and throw on error wrapped in the same retry logic
as before. This is needed as a short term fix for the DHCP race
condition where we try to initialise the App Store before the device has
an IP.
  • Loading branch information
lukechilds committed Apr 5, 2024
1 parent 5b1fa4a commit 70b105b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
7 changes: 1 addition & 6 deletions packages/umbreld/source/modules/apps/app-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,7 @@ export default class AppRepository {
this.logger.verbose(`${this.url} is already up to date`)
} else {
this.logger.verbose(`Newer version of ${this.url} available, updating`)
try {
await this.atomicClone()
} catch (error) {
this.logger.error(`Update failed for ${this.url}: ${(error as Error).message}`)
}

await this.atomicClone()
this.logger.verbose(`Updated ${this.url}!`)
}

Expand Down
37 changes: 25 additions & 12 deletions packages/umbreld/source/modules/apps/app-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,34 @@ export default class AppStore {
}

// Initialise repositories
this.logger.log(`Initialising repositories...`)
await pRetry(() => this.update(), {
onFailedAttempt: (error) => {
this.logger.error(
`Attempt ${error.attemptNumber} initialising repositories failed. There are ${error.retriesLeft} retries left.`,
)
},
retries: 5, // This will do exponential backoff for 1s, 2s, 4s, 8s, 16s
})
await this.update()
this.logger.log(`Repositories initialised!`)
this.logger.log(`Initialising default repository...`)
try {
const repositories = await this.getRepositories()
const defaultRepository = repositories.find((repository) => repository.url === this.defaultAppStoreRepo)
if (!defaultRepository) throw new Error(`Default repository ${this.defaultAppStoreRepo} not found`)
await pRetry(
async () => {
await defaultRepository.update()
},
{
onFailedAttempt: (error) => {
this.logger.error(
`Failed to initialise default repository ${defaultRepository.url}: ${
(error as Error).message
}, will retry ${error.retriesLeft} more times.`,
)
},
retries: 5, // This will do exponential backoff for 1s, 2s, 4s, 8s, 16s
},
)
this.logger.log(`Default repository initialised!`)
} catch (error) {
this.logger.error(`Failed to initialise default repository: ${(error as Error).message}`)
}

// Kick off update loop
this.logger.log(`Checking repositories for updates every ${this.updateInterval}`)
this.#stopUpdating = runEvery(this.updateInterval, () => this.update(), {runInstantly: false})
this.#stopUpdating = runEvery(this.updateInterval, () => this.update(), {runInstantly: true})
}

async stop() {
Expand Down

0 comments on commit 70b105b

Please sign in to comment.