Skip to content

Commit

Permalink
Merge pull request #1895 from oceanprotocol/issue-1894-waitForAqua-in…
Browse files Browse the repository at this point in the history
…terval

make retries and interval bigger & configurable on waitForAqua
  • Loading branch information
paulo-ocean authored Jan 8, 2025
2 parents 4437713 + 4b01979 commit 9bd733b
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 32 deletions.
4 changes: 2 additions & 2 deletions CodeExamples.md
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ Now we can make the contract call
)
console.log(`Consumer ${FRE_NFT_SYMBOL} balance after swap: ${consumerDTBalance}`)

const resolvedDDO = await aquarius.waitForAqua(fixedDDO.id)
const resolvedDDO = await aquarius.waitForIndexer(fixedDDO.id)
assert(resolvedDDO, 'Cannot fetch DDO from Aquarius')

```
Expand Down Expand Up @@ -726,7 +726,7 @@ Now we need to encrypt file(s) using provider
`Consumer ${DISP_NFT_SYMBOL} balance after dispense: ${consumerDTBalance}`
)

const resolvedDDO = await aquarius.waitForAqua(fixedDDO.id)
const resolvedDDO = await aquarius.waitForIndexer(fixedDDO.id)
assert(resolvedDDO, 'Cannot fetch DDO from Aquarius')

datatoken = new Datatoken(consumerAccount, await consumerAccount.getChainId())
Expand Down
4 changes: 2 additions & 2 deletions ComputeExamples.md
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,8 @@ Now, let's check that we successfully published a algorithm (create NFT + Datato

### 7.1 Resolve published datasets and algorithms
```Typescript
resolvedDatasetDdo = await aquariusInstance.waitForAqua(datasetId)
resolvedAlgorithmDdo = await aquariusInstance.waitForAqua(algorithmId)
resolvedDatasetDdo = await aquariusInstance.waitForIndexer(datasetId)
resolvedAlgorithmDdo = await aquariusInstance.waitForIndexer(algorithmId)
```
<!--
assert(resolvedDatasetDdo, 'Cannot fetch DDO from Aquarius')
Expand Down
10 changes: 6 additions & 4 deletions docs/classes/Aquarius.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
- [querySearch](Aquarius.md#querysearch)
- [resolve](Aquarius.md#resolve)
- [validate](Aquarius.md#validate)
- [waitForAqua](Aquarius.md#waitforaqua)
- [waitForIndexer](Aquarius.md#waitForIndexer)

## Constructors

Expand Down Expand Up @@ -146,11 +146,11 @@ Validate DDO content

___

### waitForAqua
### waitForIndexer

**waitForAqua**(`did`, `txid?`, `signal?`): `Promise`<[`Asset`](../interfaces/Asset.md)\>
**waitForIndexer**(`did`, `txid?`, `signal?`, `interval=3000`,`maxRetries=100`): `Promise`<[`Asset`](../interfaces/Asset.md)\>

Blocks until Aqua will cache the did (or the update for that did) or timeouts
Blocks until Indexer will cache the did (or the update for that did) or timeouts

#### Parameters

Expand All @@ -159,6 +159,8 @@ Blocks until Aqua will cache the did (or the update for that did) or timeouts
| `did` | `string` | DID of the asset. |
| `txid?` | `string` | used when the did exists and we expect an update with that txid. |
| `signal?` | `AbortSignal` | abort signal |
| `interval` | `number` | retry interval in miliseconds. Default is 3000 |
| `maxRetries` | `number` | max number of retries. Default is 100 |

#### Returns

Expand Down
17 changes: 12 additions & 5 deletions src/services/Aquarius.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,25 @@ export class Aquarius {
}

/**
* Blocks until Aqua will cache the did (or the update for that did) or timeouts
* Blocks until Indexer will cache the did (or the update for that did) or timeouts
* @param {string} did DID of the asset.
* @param {string} txid used when the did exists and we expect an update with that txid.
* @param {AbortSignal} signal abort signal
* @return {Promise<Asset>} DDO of the asset.
*/
public async waitForAqua(
public async waitForIndexer(
did: string,
txid?: string,
signal?: AbortSignal
signal?: AbortSignal,
interval: number = 3000,
maxRetries: number = 100
): Promise<Asset> {
let tries = 0
// lets have a cap to prevent possible abuse as well
if (maxRetries > 500) {
LoggerInstance.warn('Max Limit exceeded, defaulting to 500 retries.')
maxRetries = 500
}
do {
try {
const path = this.aquariusURL + '/api/aquarius/assets/ddo/' + did
Expand All @@ -80,9 +87,9 @@ export class Aquarius {
} catch (e) {
// do nothing
}
await sleep(1500)
await sleep(interval)
tries++
} while (tries < 100)
} while (tries < maxRetries)
return null
}

Expand Down
4 changes: 2 additions & 2 deletions test/integration/CodeExamples.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ describe('Marketplace flow tests', async () => {
)
console.log(`Consumer ${FRE_NFT_SYMBOL} balance after swap: ${consumerDTBalance}`)

const resolvedDDO = await aquarius.waitForAqua(fixedDDO.id)
const resolvedDDO = await aquarius.waitForIndexer(fixedDDO.id)
assert(resolvedDDO, 'Cannot fetch DDO from Aquarius')

/// ```
Expand Down Expand Up @@ -726,7 +726,7 @@ describe('Marketplace flow tests', async () => {
`Consumer ${DISP_NFT_SYMBOL} balance after dispense: ${consumerDTBalance}`
)

const resolvedDDO = await aquarius.waitForAqua(fixedDDO.id)
const resolvedDDO = await aquarius.waitForIndexer(fixedDDO.id)
assert(resolvedDDO, 'Cannot fetch DDO from Aquarius')

datatoken = new Datatoken(consumerAccount, await consumerAccount.getChainId())
Expand Down
4 changes: 2 additions & 2 deletions test/integration/ComputeExamples.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,8 @@ describe('Compute-to-data example tests', async () => {

it('7.1 Resolve published datasets and algorithms', async () => {
/// ```Typescript
resolvedDatasetDdo = await aquariusInstance.waitForAqua(datasetId)
resolvedAlgorithmDdo = await aquariusInstance.waitForAqua(algorithmId)
resolvedDatasetDdo = await aquariusInstance.waitForIndexer(datasetId)
resolvedAlgorithmDdo = await aquariusInstance.waitForIndexer(algorithmId)
/// ```
/// <!--
assert(resolvedDatasetDdo, 'Cannot fetch DDO from Aquarius')
Expand Down
8 changes: 4 additions & 4 deletions test/integration/ComputeFlow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,13 @@ describe('Compute flow tests', async () => {
delay(10000)

it('should resolve published datasets and algorithms', async () => {
resolvedDdoWith5mTimeout = await aquarius.waitForAqua(ddoWith5mTimeoutId)
resolvedDdoWith5mTimeout = await aquarius.waitForIndexer(ddoWith5mTimeoutId)
assert(resolvedDdoWith5mTimeout, 'Cannot fetch DDO from Aquarius')
resolvedDdoWithNoTimeout = await aquarius.waitForAqua(ddoWithNoTimeoutId)
resolvedDdoWithNoTimeout = await aquarius.waitForIndexer(ddoWithNoTimeoutId)
assert(resolvedDdoWithNoTimeout, 'Cannot fetch DDO from Aquarius')
resolvedAlgoDdoWith5mTimeout = await aquarius.waitForAqua(algoDdoWith5mTimeoutId)
resolvedAlgoDdoWith5mTimeout = await aquarius.waitForIndexer(algoDdoWith5mTimeoutId)
assert(resolvedAlgoDdoWith5mTimeout, 'Cannot fetch DDO from Aquarius')
resolvedAlgoDdoWithNoTimeout = await aquarius.waitForAqua(algoDdoWithNoTimeoutId)
resolvedAlgoDdoWithNoTimeout = await aquarius.waitForIndexer(algoDdoWithNoTimeoutId)
assert(resolvedAlgoDdoWithNoTimeout, 'Cannot fetch DDO from Aquarius')
})

Expand Down
18 changes: 9 additions & 9 deletions test/integration/PublishEditConsume.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,19 +304,19 @@ describe('Publish consume test', async () => {
delay(10000) // let's wait for aquarius to index the assets

it('Resolve published assets', async () => {
resolvedUrlAssetDdo = await aquarius.waitForAqua(urlAssetId)
resolvedUrlAssetDdo = await aquarius.waitForIndexer(urlAssetId)
assert(resolvedUrlAssetDdo, 'Cannot fetch url DDO from Aquarius')

resolvedArweaveAssetDdo = await aquarius.waitForAqua(arweaveAssetId)
resolvedArweaveAssetDdo = await aquarius.waitForIndexer(arweaveAssetId)
assert(resolvedArweaveAssetDdo, 'Cannot fetch arwave DDO from Aquarius')

resolvedIpfsAssetDdo = await aquarius.waitForAqua(ipfsAssetId)
resolvedIpfsAssetDdo = await aquarius.waitForIndexer(ipfsAssetId)
assert(resolvedIpfsAssetDdo, 'Cannot fetch ipfs DDO from Aquarius')

resolvedOnchainAssetDdo = await aquarius.waitForAqua(onchainAssetId)
resolvedOnchainAssetDdo = await aquarius.waitForIndexer(onchainAssetId)
assert(resolvedOnchainAssetDdo, 'Cannot fetch onchain DDO from Aquarius')

resolvedGraphqlAssetDdo = await aquarius.waitForAqua(grapqlAssetId)
resolvedGraphqlAssetDdo = await aquarius.waitForIndexer(grapqlAssetId)
assert(resolvedGraphqlAssetDdo, 'Cannot fetch graphql DDO from Aquarius')
})

Expand Down Expand Up @@ -557,19 +557,19 @@ describe('Publish consume test', async () => {
delay(10000) // let's wait for aquarius to index the updated ddo's

it('Should resolve updated datasets', async () => {
resolvedUrlAssetDdoAfterUpdate = await aquarius.waitForAqua(urlAssetId)
resolvedUrlAssetDdoAfterUpdate = await aquarius.waitForIndexer(urlAssetId)
assert(resolvedUrlAssetDdoAfterUpdate, 'Cannot fetch url DDO from Aquarius')

resolvedArweaveAssetDdoAfterUpdate = await aquarius.waitForAqua(arweaveAssetId)
resolvedArweaveAssetDdoAfterUpdate = await aquarius.waitForIndexer(arweaveAssetId)
assert(resolvedArweaveAssetDdoAfterUpdate, 'Cannot fetch arwave DDO from Aquarius')
// To be fixed in #1849
// resolvedIpfsAssetDdoAfterUpdate = await aquarius.waitForAqua(ipfsAssetId)
// assert(resolvedIpfsAssetDdoAfterUpdate, 'Cannot fetch ipfs DDO from Aquarius')

resolvedOnchainAssetDdoAfterUpdate = await aquarius.waitForAqua(onchainAssetId)
resolvedOnchainAssetDdoAfterUpdate = await aquarius.waitForIndexer(onchainAssetId)
assert(resolvedOnchainAssetDdoAfterUpdate, 'Cannot fetch onchain DDO from Aquarius')

resolvedGraphqlAssetDdoAfterUpdate = await aquarius.waitForAqua(grapqlAssetId)
resolvedGraphqlAssetDdoAfterUpdate = await aquarius.waitForIndexer(grapqlAssetId)
assert(resolvedGraphqlAssetDdoAfterUpdate, 'Cannot fetch onchain DDO from Aquarius')
})
})
Expand Down
4 changes: 2 additions & 2 deletions test/integration/PublishFlows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ describe('Publish tests', async () => {
})

it('should resolve the fixed price dataset', async () => {
const resolvedDDO = await aquarius.waitForAqua(fixedPricedDID)
const resolvedDDO = await aquarius.waitForIndexer(fixedPricedDID)
assert(resolvedDDO, 'Cannot fetch DDO from Aquarius')
}).timeout(40000)

Expand Down Expand Up @@ -316,7 +316,7 @@ describe('Publish tests', async () => {
delay(19000)

it('should resolve the free dataset', async () => {
const resolvedDDO = await aquarius.waitForAqua(dispenserDID)
const resolvedDDO = await aquarius.waitForIndexer(dispenserDID)
assert(resolvedDDO, 'Cannot fetch DDO from Aquarius')
})
})

0 comments on commit 9bd733b

Please sign in to comment.