Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying retry policy for v4 model #696

Merged
merged 2 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/coreApi/converters/fromCoreFunctionMetadata.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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');
}
}
27 changes: 27 additions & 0 deletions types-core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
hossam-nasr marked this conversation as resolved.
Show resolved Hide resolved
}

/**
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
}