-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add storage retry strategy override example (#1427)
* chore: add storage retry strategy override example * use FixedTimeoutRetryStrategy instead * fix lint error
- Loading branch information
Showing
2 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters