Skip to content

Commit

Permalink
Allow specifying retry policy for v4 model (#696)
Browse files Browse the repository at this point in the history
  • Loading branch information
ejizba committed Jun 28, 2023
1 parent 2f73dfb commit 6ae7adf
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/coreApi/converters/fromCoreFunctionMetadata.ts
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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');
}
}
28 changes: 28 additions & 0 deletions src/coreApi/converters/toCoreFunctionMetadata.ts
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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');
}
}
29 changes: 28 additions & 1 deletion types-core/index.d.ts
Expand Up @@ -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 {
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -298,6 +303,8 @@ declare module '@azure/functions-core' {
functionId?: string | null;

managedDependencyEnabled?: boolean | null;

retryOptions?: RpcRetryOptions | null;
}

interface RpcStatusResult {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
}

0 comments on commit 6ae7adf

Please sign in to comment.