Skip to content

Commit

Permalink
feat(retry): add 6x 500ms spaced retries
Browse files Browse the repository at this point in the history
  • Loading branch information
CanisHelix committed Mar 15, 2024
1 parent 5e98b19 commit 8bcc3da
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
33 changes: 22 additions & 11 deletions services/youtrack/youtrack-issues.service.js
Expand Up @@ -5,6 +5,10 @@ import { metric } from '../text-formatters.js'
import { description } from './youtrack-helper.js'
import YoutrackBase from './youtrack-base.js'

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}

const schema = Joi.object({
count: Joi.number().required(),
$type: Joi.equal('IssueCountResponse'),
Expand Down Expand Up @@ -71,18 +75,25 @@ export default class YoutrackIssues extends YoutrackBase {
})
}

async handle({ project }, { youtrack_url: baseUrl, query }) {
const data = await this.fetch({
baseUrl,
query: `project: ${project} ${query}`,
})

if (data.count === -1) {
throw new InvalidResponse({
prettyMessage: 'processing',
cacheSeconds: 10,
async handle({ project }, { youtrack_url: baseUrl, query = '' }) {
for (let i = 0; i < 6; i++) {
// 6 trials
const data = await this.fetch({
baseUrl,
query: `project: ${project} ${query}`,
})

if (data.count === -1) {
await sleep(500)
continue
}

return this.constructor.render({ count: data.count })
}
return this.constructor.render({ count: data.count })

throw new InvalidResponse({
prettyMessage: 'invalid',
cacheSeconds: 10,
})
}
}
5 changes: 2 additions & 3 deletions services/youtrack/youtrack-issues.tester.js
@@ -1,4 +1,3 @@
import Joi from 'joi'
import { createServiceTester } from '../tester.js'
import { isMetric } from '../test-validators.js'

Expand All @@ -10,14 +9,14 @@ t.create('Issues (DEMO) (Cloud)')
)
.expectBadge({
label: 'issues',
message: Joi.alternatives().try(isMetric, 'processing', 'timeout'),
message: isMetric,
})

t.create('Issues (DEMO) (Empty Query) (Cloud)')
.get('/DEMO.json?youtrack_url=https://shields.youtrack.cloud')
.expectBadge({
label: 'issues',
message: Joi.alternatives().try(isMetric, 'processing', 'timeout'),
message: isMetric,
})

t.create('Issues (DEMO) (Invalid State) (Cloud Hosted)')
Expand Down

0 comments on commit 8bcc3da

Please sign in to comment.