From 6ae7adfb2a69f7b2ba07c262d6f945cfd8a02341 Mon Sep 17 00:00:00 2001 From: Eric Jizba Date: Tue, 27 Jun 2023 18:54:22 -0700 Subject: [PATCH] Allow specifying retry policy for v4 model (#696) --- .../converters/fromCoreFunctionMetadata.ts | 28 ++++++++++++++++++ .../converters/toCoreFunctionMetadata.ts | 28 ++++++++++++++++++ types-core/index.d.ts | 29 ++++++++++++++++++- 3 files changed, 84 insertions(+), 1 deletion(-) diff --git a/src/coreApi/converters/fromCoreFunctionMetadata.ts b/src/coreApi/converters/fromCoreFunctionMetadata.ts index 0b5d81fb..72bc5a07 100644 --- a/src/coreApi/converters/fromCoreFunctionMetadata.ts +++ b/src/coreApi/converters/fromCoreFunctionMetadata.ts @@ -12,6 +12,7 @@ export function fromCoreFunctionMetadata(data: coreTypes.RpcFunctionMetadata): r ...data, bindings: fromCoreBindings(data.bindings), status: fromCoreStatusResult(data.status), + retryOptions: fromCoreRetryOptions(data.retryOptions), }; return ensureKeysMatch(data, result); } @@ -74,3 +75,30 @@ function fromCoreBindingDirection( return handleDefaultEnumCase(data, 'CoreRpcBindingDirection'); } } + +function fromCoreRetryOptions( + data: coreTypes.RpcRetryOptions | null | undefined +): rpc.IRpcRetryOptions | null | undefined { + if (data) { + const result = { + ...data, + retryStrategy: fromCoreRetryStrategy(data.retryStrategy), + }; + return ensureKeysMatch(data, result); + } else { + return data; + } +} + +function fromCoreRetryStrategy( + data: coreTypes.RpcRetryStrategy | null | undefined +): rpc.RpcRetryOptions.RetryStrategy | null | undefined { + switch (data) { + case 'exponentialBackoff': + return rpc.RpcRetryOptions.RetryStrategy.exponential_backoff; + case 'fixedDelay': + return rpc.RpcRetryOptions.RetryStrategy.fixed_delay; + default: + return handleDefaultEnumCase(data, 'CoreRpcRetryStrategy'); + } +} diff --git a/src/coreApi/converters/toCoreFunctionMetadata.ts b/src/coreApi/converters/toCoreFunctionMetadata.ts index d0372ab0..385c390c 100644 --- a/src/coreApi/converters/toCoreFunctionMetadata.ts +++ b/src/coreApi/converters/toCoreFunctionMetadata.ts @@ -12,6 +12,7 @@ export function toCoreFunctionMetadata(data: rpc.IRpcFunctionMetadata): coreType ...data, bindings: toCoreBindings(data.bindings), status: toCoreStatusResult(data.status), + retryOptions: toCoreRetryOptions(data.retryOptions), }; return ensureKeysMatch(data, result); } @@ -74,3 +75,30 @@ function toCoreBindingDirection( return handleDefaultEnumCase(data, 'RpcBindingDirection'); } } + +function toCoreRetryOptions( + data: rpc.IRpcRetryOptions | null | undefined +): coreTypes.RpcRetryOptions | null | undefined { + if (data) { + const result = { + ...data, + retryStrategy: toCoreRetryStrategy(data.retryStrategy), + }; + return ensureKeysMatch(data, result); + } else { + return data; + } +} + +function toCoreRetryStrategy( + data: rpc.RpcRetryOptions.RetryStrategy | null | undefined +): coreTypes.RpcRetryStrategy | null | undefined { + switch (data) { + case rpc.RpcRetryOptions.RetryStrategy.exponential_backoff: + return 'exponentialBackoff'; + case rpc.RpcRetryOptions.RetryStrategy.fixed_delay: + return 'fixedDelay'; + default: + return handleDefaultEnumCase(data, 'RpcRetryStrategy'); + } +} diff --git a/types-core/index.d.ts b/types-core/index.d.ts index 252433bd..73d1642e 100644 --- a/types-core/index.d.ts +++ b/types-core/index.d.ts @@ -22,7 +22,7 @@ declare module '@azure/functions-core' { function registerFunction(metadata: FunctionMetadata, callback: FunctionCallback): Disposable; /** - * A slimmed down version of `RpcFunctionMetadata` that includes the minimum amount of information needed to register a function + * A slimmed down version of `RpcFunctionMetadata` that includes only the properties respected as a part of the `registerFunction` api * NOTE: All properties on this object need to be deterministic to support the multiple worker scenario. More info here: https://github.com/Azure/azure-functions-nodejs-worker/issues/638 */ interface FunctionMetadata { @@ -43,6 +43,11 @@ declare module '@azure/functions-core' { * A dictionary of binding name to binding info */ bindings: { [name: string]: RpcBindingInfo }; + + /** + * The retry policy options + */ + retryOptions?: RpcRetryOptions; } /** @@ -298,6 +303,8 @@ declare module '@azure/functions-core' { functionId?: string | null; managedDependencyEnabled?: boolean | null; + + retryOptions?: RpcRetryOptions | null; } interface RpcStatusResult { @@ -352,6 +359,20 @@ declare module '@azure/functions-core' { type RpcBindingDataType = 'undefined' | 'string' | 'binary' | 'stream'; + interface RpcRetryOptions { + maxRetryCount?: number | null; + + delayInterval?: RpcDuration | null; + + minimumInterval?: RpcDuration | null; + + maximumInterval?: RpcDuration | null; + + retryStrategy?: RpcRetryStrategy | null; + } + + type RpcRetryStrategy = 'exponentialBackoff' | 'fixedDelay'; + interface RpcTypedData { string?: string | null; @@ -508,6 +529,12 @@ declare module '@azure/functions-core' { nanos?: number | null; } + interface RpcDuration { + seconds?: number | Long | null; + + nanos?: number | null; + } + type RpcHttpCookieSameSite = 'none' | 'lax' | 'strict' | 'explicitNone'; // #endregion rpc types }