Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/api-cardano-db-hasura/test/ada.query.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from 'path'

import { DocumentNode } from 'graphql'
import pRetry from 'p-retry'
import util from '@cardano-graphql/util'
import { TestClient } from '@cardano-graphql/util-dev'
import { testClient } from './util'
Expand All @@ -23,16 +24,17 @@ describe('ada', () => {
})

it('returns ada supply information', async () => {
const result = await client.query({
query: await loadQueryNode('adaSupply')
})
const query = await loadQueryNode('adaSupply')
const result = await pRetry(
() => client.query({ query }),
{ retries: 40, minTimeout: 3000, factor: 1 }
)
const { ada } = result.data
const circulatingSupply = new BigNumber(ada.supply.circulating).toNumber()
const maxSupply = new BigNumber(ada.supply.max).toNumber()
const totalSupply = new BigNumber(ada.supply.total).toNumber()
expect(maxSupply).toEqual(genesis.shelley.maxLovelaceSupply)
expect(maxSupply).toBeGreaterThan(circulatingSupply)
// expect(totalSupply).toBeGreaterThan(circulatingSupply)
expect(totalSupply).toBeLessThan(maxSupply)
})
})
9 changes: 9 additions & 0 deletions packages/util/src/data_fetching/DataFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { FetchFunction } from './index'
import { clearIntervalAsync, setIntervalAsync, SetIntervalAsyncTimer } from 'set-interval-async/dynamic'
import { dummyLogger, Logger } from 'ts-log'

const INITIAL_FETCH_RETRY_INTERVAL = 15000
const INITIAL_FETCH_MAX_ATTEMPTS = 40

export class DataFetcher<DataValue> {
private pollingQueryTimer: SetIntervalAsyncTimer
private fetch: () => Promise<void>
Expand Down Expand Up @@ -29,6 +32,12 @@ export class DataFetcher<DataValue> {

public async initialize () {
await this.fetch()
let initialAttempts = 0
while (this.value === undefined && initialAttempts < INITIAL_FETCH_MAX_ATTEMPTS) {
initialAttempts++
await new Promise(resolve => setTimeout(resolve, INITIAL_FETCH_RETRY_INTERVAL))
await this.fetch()
}
this.logger.debug({ module: 'DataFetcher', instance: this.name, value: this.value }, 'Initial value fetched')
this.pollingQueryTimer = setIntervalAsync(async () => {
await this.fetch()
Expand Down
Loading