Skip to content

Commit

Permalink
Retry failed Neucore requests up to 5 times
Browse files Browse the repository at this point in the history
Ref #65
  • Loading branch information
cmd-johnson committed Jul 25, 2022
1 parent fe9007d commit 05f63dd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@ping-board/common": "workspace:packages/common",
"@slack/web-api": "^6.6.0",
"client-oauth2": "^4.3.3",
"cockatiel": "^3.0.0-beta.1",
"dayjs": "^1.10.7",
"http-errors": "^1.8.1",
"jsonwebtoken": "^8.5.1",
Expand Down
12 changes: 11 additions & 1 deletion packages/backend/src/neucore/neucore-group-cache.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { handleAll, retry, ExponentialBackoff } from 'cockatiel'
import { InMemoryTTLCache } from '../util/in-memory-ttl-cache'
import { NeucoreGroupsProvider } from '../middleware/user-roles'
import { NeucoreClient } from './neucore-client'
Expand All @@ -9,11 +10,20 @@ export class NeucoreGroupCache implements NeucoreGroupsProvider {
neucoreClient: NeucoreClient
cacheTTL: number
}) {
const policy = retry(handleAll, {
backoff: new ExponentialBackoff(),
maxAttempts: 5,
})

this.#cache = new InMemoryTTLCache({
defaultTTL: options.cacheTTL,
get: async characterId => {
console.log('getting neucore groups for', characterId)
const groups = await options.neucoreClient.getCharacterGroups(characterId)

const groups = await policy.execute(() =>
options.neucoreClient.getCharacterGroups(characterId)
)

return { value: groups.map(g => g.name) }
},
})
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2127,6 +2127,7 @@ __metadata:
"@typescript-eslint/eslint-plugin": ^4.33.0
"@typescript-eslint/parser": ^4.33.0
client-oauth2: ^4.3.3
cockatiel: ^3.0.0-beta.1
dayjs: ^1.10.7
eslint: ^7.32.0
http-errors: ^1.8.1
Expand Down Expand Up @@ -5732,6 +5733,13 @@ __metadata:
languageName: node
linkType: hard

"cockatiel@npm:^3.0.0-beta.1":
version: 3.0.0-beta.1
resolution: "cockatiel@npm:3.0.0-beta.1"
checksum: 9cc8571cd418c9e72cb1cd8b2f66e0626b1a8851d92fa57a8621f1bbc06ee0845c6971aa88d9de0589cbc5a975b6ad27f549196ece6b8a69529986408f246439
languageName: node
linkType: hard

"code-point-at@npm:^1.0.0":
version: 1.1.0
resolution: "code-point-at@npm:1.1.0"
Expand Down

0 comments on commit 05f63dd

Please sign in to comment.