Skip to content

Commit

Permalink
add process.env options for wait for indexing max retries and interval
Browse files Browse the repository at this point in the history
  • Loading branch information
paulo-ocean committed Jan 9, 2025
1 parent ae578dd commit 9d2ac40
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 10 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ export PROVIDER_URL='XXXX'
export ADDRESS_FILE='path-to-address-file'
```

- Optional set INDEXING_MAX_RETRIES to the max number of retries when waiting for an asset to be indexed. Default is 100 retries max.

```
export INDEXING_MAX_RETRIES='100'
```

- Optional set INDEXING_RETRY_INTERVAL to the interval (in miliseconds) for each retry when waiting for an asset to be indexed. Default is 3 seconds.

```
export INDEXING_RETRY_INTERVAL='3000'
```

### Build the TypeScript code

```
Expand Down
25 changes: 15 additions & 10 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
downloadFile,
isOrderable,
getMetadataURI,
getIndexingWaitSettings,
IndexerWaitParams,
} from "./helpers";
import {
Aquarius,
Expand All @@ -34,11 +36,14 @@ export class Commands {
public aquarius: Aquarius;
public providerUrl: string;
public macOsProviderUrl: string;
// optional settings for indexing wait time
private indexingParams: IndexerWaitParams;

constructor(signer: Signer, network: string | number, config?: Config) {
this.signer = signer;
this.config = config || new ConfigHelper().getConfig(network);
this.providerUrl = process.env.NODE_URL || process.env.PROVIDER_URL || this.config.providerUri;
this.indexingParams = getIndexingWaitSettings();
if (
!process.env.PROVIDER_URL && !process.env.NODE_URL &&
this.config.chainId === 8996 &&
Expand Down Expand Up @@ -142,7 +147,7 @@ export class Commands {
}

public async editAsset(args: string[]) {
const asset = await this.aquarius.waitForIndexer(args[1]);
const asset = await this.aquarius.waitForIndexer(args[1],null,null, this.indexingParams.retryInterval, this.indexingParams.maxRetries);
if (!asset) {
console.error(
"Error fetching DDO " + args[1] + ". Does this asset exists?"
Expand Down Expand Up @@ -178,7 +183,7 @@ export class Commands {

public async getDDO(args: string[]) {
console.log("Resolving Asset with DID: " + args[1]);
const resolvedDDO = await this.aquarius.waitForIndexer(args[1]);
const resolvedDDO = await this.aquarius.waitForIndexer(args[1],null,null, this.indexingParams.retryInterval, this.indexingParams.maxRetries);
if (!resolvedDDO) {
console.error(
"Error fetching Asset with DID: " +
Expand All @@ -189,7 +194,7 @@ export class Commands {
}

public async download(args: string[]) {
const dataDdo = await this.aquarius.waitForIndexer(args[1]);
const dataDdo = await this.aquarius.waitForIndexer(args[1],null,null, this.indexingParams.retryInterval, this.indexingParams.maxRetries);
if (!dataDdo) {
console.error(
"Error fetching DDO " + args[1] + ". Does this asset exists?"
Expand Down Expand Up @@ -258,7 +263,7 @@ export class Commands {
const ddos = [];

for (const dataset in inputDatasets) {
const dataDdo = await this.aquarius.waitForIndexer(inputDatasets[dataset]);
const dataDdo = await this.aquarius.waitForIndexer(inputDatasets[dataset],null,null, this.indexingParams.retryInterval, this.indexingParams.maxRetries);
if (!dataDdo) {
console.error(
"Error fetching DDO " + dataset[1] + ". Does this asset exists?"
Expand All @@ -277,7 +282,7 @@ export class Commands {
? this.macOsProviderUrl
: ddos[0].services[0].serviceEndpoint;

const algoDdo = await this.aquarius.waitForIndexer(args[2]);
const algoDdo = await this.aquarius.waitForIndexer(args[2],null,null, this.indexingParams.retryInterval, this.indexingParams.maxRetries);
if (!algoDdo) {
console.error(
"Error fetching DDO " + args[1] + ". Does this asset exists?"
Expand Down Expand Up @@ -436,7 +441,7 @@ export class Commands {
}

public async computeStop(args: string[]) {
const dataDdo = await this.aquarius.waitForIndexer(args[1]);
const dataDdo = await this.aquarius.waitForIndexer(args[1],null,null, this.indexingParams.retryInterval, this.indexingParams.maxRetries);
if (!dataDdo) {
console.error(
"Error fetching DDO " + args[1] + ". Does this asset exists?"
Expand Down Expand Up @@ -468,7 +473,7 @@ export class Commands {
}

public async allowAlgo(args: string[]) {
const asset = await this.aquarius.waitForIndexer(args[1]);
const asset = await this.aquarius.waitForIndexer(args[1],null,null, this.indexingParams.retryInterval, this.indexingParams.maxRetries);
if (!asset) {
console.error(
"Error fetching DDO " + args[1] + ". Does this asset exists?"
Expand All @@ -491,7 +496,7 @@ export class Commands {
);
return;
}
const algoAsset = await this.aquarius.waitForIndexer(args[2]);
const algoAsset = await this.aquarius.waitForIndexer(args[2],null,null, this.indexingParams.retryInterval, this.indexingParams.maxRetries);
if (!algoAsset) {
console.error(
"Error fetching DDO " + args[2] + ". Does this asset exists?"
Expand Down Expand Up @@ -538,7 +543,7 @@ export class Commands {
}

public async disallowAlgo(args: string[]) {
const asset = await this.aquarius.waitForIndexer(args[1]);
const asset = await this.aquarius.waitForIndexer(args[1],null,null, this.indexingParams.retryInterval, this.indexingParams.maxRetries);
if (!asset) {
console.error(
"Error fetching DDO " + args[1] + ". Does this asset exists?"
Expand Down Expand Up @@ -603,7 +608,7 @@ export class Commands {
// args[3] - agreementId
const hasAgreementId = args.length === 4;

const dataDdo = await this.aquarius.waitForIndexer(args[1]);
const dataDdo = await this.aquarius.waitForIndexer(args[1],null,null, this.indexingParams.retryInterval, this.indexingParams.maxRetries);
if (!dataDdo) {
console.error(
"Error fetching DDO " + args[1] + ". Does this asset exists?"
Expand Down
34 changes: 34 additions & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,4 +433,38 @@ export function isPrivateIP(ip): boolean {
}
return ip
}
// for waiting for an asset to index
export interface IndexerWaitParams {
maxRetries: number,
retryInterval: number
}

// defines how much time we wait for an asset to index + the interval for retries
export function getIndexingWaitSettings(): IndexerWaitParams {
const indexingParams: IndexerWaitParams = {
maxRetries: 100, // 100 retries
retryInterval: 3000 // retries every 3 seconds
}
try {

if(!isNaN(Number(process.env.INDEXING_RETRY_INTERVAL))) {

indexingParams.retryInterval = Number(process.env.INDEXING_RETRY_INTERVAL)
if(indexingParams.retryInterval < 0) {
indexingParams.retryInterval = 3000
}

}
if(!isNaN(Number(process.env.INDEXING_MAX_RETRIES))) {

indexingParams.maxRetries = Number(process.env.INDEXING_MAX_RETRIES)
if(indexingParams.maxRetries < 0) {
indexingParams.maxRetries = 100
}
}
}catch(err) {
console.error('Error getting indexing wait arguments:' , err)
}

return indexingParams
}

0 comments on commit 9d2ac40

Please sign in to comment.