Skip to content

Commit

Permalink
chore: add storage retry strategy override example (#1427)
Browse files Browse the repository at this point in the history
* chore: add storage retry strategy override example

* use FixedTimeoutRetryStrategy instead

* fix lint error
  • Loading branch information
anitarua authored Aug 30, 2024
1 parent 52a4b98 commit ae97ce6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
44 changes: 44 additions & 0 deletions examples/nodejs/storage/advanced.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {
CredentialProvider,
DefaultMomentoLoggerFactory,
DefaultMomentoLoggerLevel,
FixedTimeoutRetryStrategy,
ListStoresResponse,
MomentoLoggerFactory,
PreviewStorageClient,
StorageConfigurations,
} from '@gomomento/sdk';

async function main() {
// You can customize your log level or provide your own logger factory to
// integrate with your favorite logging framework
const loggerFactory: MomentoLoggerFactory = new DefaultMomentoLoggerFactory(DefaultMomentoLoggerLevel.DEBUG);
const logger = loggerFactory.getLogger('AdvancedStorageExample');

// You can specify the logger factory and override the default RetryStrategy
const storageClient = new PreviewStorageClient({
configuration: StorageConfigurations.Laptop.latest(loggerFactory).withRetryStrategy(
new FixedTimeoutRetryStrategy({
loggerFactory: loggerFactory,
responseDataReceivedTimeoutMillis: 2000,
retryDelayIntervalMillis: 200,
})
),
credentialProvider: CredentialProvider.fromEnvironmentVariable('MOMENTO_API_KEY'),
});

const response = await storageClient.listStores();
switch (response.type) {
case ListStoresResponse.Success:
logger.info('Stores:', response.stores());
break;
case ListStoresResponse.Error:
logger.error('Error listing stores:', response.innerException());
break;
}
}

main().catch(e => {
console.error('An error occurred! ', e);
throw e;
});
3 changes: 2 additions & 1 deletion examples/nodejs/storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
"prebuild": "eslint . --ext .ts",
"build": "tsc",
"basic": "tsc && node dist/basic.js",
"advanced": "tsc && node dist/advanced.js",
"doc-examples": "tsc && node dist/doc-examples-js-apis.js",
"validate-examples": "tsc && node dist/doc-example-files/doc-examples-js-apis.js && node dist/doc-example-files/cheat-sheet-main.js",
"validate-examples": "tsc && node dist/doc-example-files/doc-examples-js-apis.js && node dist/doc-example-files/cheat-sheet-main.js && node dist/basic.js && node dist/advanced.js",
"test": "jest",
"lint": "eslint . --ext .ts",
"format": "eslint . --ext .ts --fix"
Expand Down

0 comments on commit ae97ce6

Please sign in to comment.