Skip to content

Commit

Permalink
Add retry to runtime extension
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewFossAWS committed Aug 22, 2023
1 parent dab49f8 commit 1b34092
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changeset/chilled-lies-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@smithy/smithy-client": minor
"@smithy/types": minor
---

Add retry to runtime extension
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import type { DefaultExtensionConfiguration } from "@smithy/types";

import { getChecksumConfiguration, resolveChecksumRuntimeConfig } from "./checksum";
import { getRetryConfiguration, resolveRetryRuntimeConfig } from "./retry";

/**
* @internal
*/
export type DefaultExtensionConfigType = Parameters<typeof getChecksumConfiguration>[0];
export type DefaultExtensionConfigType = Parameters<typeof getChecksumConfiguration>[0] &
Parameters<typeof getRetryConfiguration>[0];

/**
* @internal
Expand All @@ -15,6 +17,7 @@ export type DefaultExtensionConfigType = Parameters<typeof getChecksumConfigurat
export const getDefaultExtensionConfiguration = (runtimeConfig: DefaultExtensionConfigType) => {
return {
...getChecksumConfiguration(runtimeConfig),
...getRetryConfiguration(runtimeConfig),
};
};

Expand All @@ -34,5 +37,6 @@ export const getDefaultClientConfiguration = getDefaultExtensionConfiguration;
export const resolveDefaultRuntimeConfig = (config: DefaultExtensionConfiguration) => {
return {
...resolveChecksumRuntimeConfig(config),
...resolveRetryRuntimeConfig(config),
};
};
27 changes: 27 additions & 0 deletions packages/smithy-client/src/extensions/retry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Provider, RetryStrategy, RetryStrategyConfiguration, RetryStrategyV2 } from "@smithy/types";

/**
* @internal
*/
export const getRetryConfiguration = (
runtimeConfig: Partial<{ retryStrategy: Provider<RetryStrategyV2 | RetryStrategy> }>
) => {
return {
_retryStrategy: runtimeConfig.retryStrategy!,
setRetryStrategy(retryStrategy: Provider<RetryStrategyV2 | RetryStrategy>): void {
this._retryStrategy = retryStrategy;
},
retryStrategy(): Provider<RetryStrategyV2 | RetryStrategy> {
return this._retryStrategy;
},
};
};

/**
* @internal
*/
export const resolveRetryRuntimeConfig = (retryStrategyConfiguration: RetryStrategyConfiguration) => {
const runtimeConfig: Partial<Record<string, Provider<RetryStrategyV2 | RetryStrategy>>> = {};
runtimeConfig.retryStrategy = retryStrategyConfiguration.retryStrategy();
return runtimeConfig;
};
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { ChecksumConfiguration } from "./checksum";
import { RetryStrategyConfiguration } from "./retry";

/**
* @internal
*
* Default extension configuration consisting various configurations for modifying a service client
*/
export interface DefaultExtensionConfiguration extends ChecksumConfiguration {}

type GetDefaultConfigurationType = (runtimeConfig: any) => DefaultExtensionConfiguration;
export interface DefaultExtensionConfiguration extends ChecksumConfiguration, RetryStrategyConfiguration {}
1 change: 1 addition & 0 deletions packages/types/src/extensions/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./defaultClientConfiguration";
export * from "./defaultExtensionConfiguration";
export { AlgorithmId, ChecksumAlgorithm, ChecksumConfiguration } from "./checksum";
export { RetryStrategyConfiguration } from "./retry";
10 changes: 10 additions & 0 deletions packages/types/src/extensions/retry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { RetryStrategyV2 } from "../retry";
import { Provider, RetryStrategy } from "../util";

/**
* @internal
*/
export interface RetryStrategyConfiguration {
setRetryStrategy(retryStrategy: Provider<RetryStrategyV2 | RetryStrategy>): void;
retryStrategy(): Provider<RetryStrategyV2 | RetryStrategy>;
}

0 comments on commit 1b34092

Please sign in to comment.