Skip to content

Commit 6ae7adf

Browse files
authored
Allow specifying retry policy for v4 model (#696)
1 parent 2f73dfb commit 6ae7adf

File tree

3 files changed

+84
-1
lines changed

3 files changed

+84
-1
lines changed

src/coreApi/converters/fromCoreFunctionMetadata.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export function fromCoreFunctionMetadata(data: coreTypes.RpcFunctionMetadata): r
1212
...data,
1313
bindings: fromCoreBindings(data.bindings),
1414
status: fromCoreStatusResult(data.status),
15+
retryOptions: fromCoreRetryOptions(data.retryOptions),
1516
};
1617
return ensureKeysMatch(data, result);
1718
}
@@ -74,3 +75,30 @@ function fromCoreBindingDirection(
7475
return handleDefaultEnumCase(data, 'CoreRpcBindingDirection');
7576
}
7677
}
78+
79+
function fromCoreRetryOptions(
80+
data: coreTypes.RpcRetryOptions | null | undefined
81+
): rpc.IRpcRetryOptions | null | undefined {
82+
if (data) {
83+
const result = {
84+
...data,
85+
retryStrategy: fromCoreRetryStrategy(data.retryStrategy),
86+
};
87+
return ensureKeysMatch(data, result);
88+
} else {
89+
return data;
90+
}
91+
}
92+
93+
function fromCoreRetryStrategy(
94+
data: coreTypes.RpcRetryStrategy | null | undefined
95+
): rpc.RpcRetryOptions.RetryStrategy | null | undefined {
96+
switch (data) {
97+
case 'exponentialBackoff':
98+
return rpc.RpcRetryOptions.RetryStrategy.exponential_backoff;
99+
case 'fixedDelay':
100+
return rpc.RpcRetryOptions.RetryStrategy.fixed_delay;
101+
default:
102+
return handleDefaultEnumCase(data, 'CoreRpcRetryStrategy');
103+
}
104+
}

src/coreApi/converters/toCoreFunctionMetadata.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export function toCoreFunctionMetadata(data: rpc.IRpcFunctionMetadata): coreType
1212
...data,
1313
bindings: toCoreBindings(data.bindings),
1414
status: toCoreStatusResult(data.status),
15+
retryOptions: toCoreRetryOptions(data.retryOptions),
1516
};
1617
return ensureKeysMatch(data, result);
1718
}
@@ -74,3 +75,30 @@ function toCoreBindingDirection(
7475
return handleDefaultEnumCase(data, 'RpcBindingDirection');
7576
}
7677
}
78+
79+
function toCoreRetryOptions(
80+
data: rpc.IRpcRetryOptions | null | undefined
81+
): coreTypes.RpcRetryOptions | null | undefined {
82+
if (data) {
83+
const result = {
84+
...data,
85+
retryStrategy: toCoreRetryStrategy(data.retryStrategy),
86+
};
87+
return ensureKeysMatch(data, result);
88+
} else {
89+
return data;
90+
}
91+
}
92+
93+
function toCoreRetryStrategy(
94+
data: rpc.RpcRetryOptions.RetryStrategy | null | undefined
95+
): coreTypes.RpcRetryStrategy | null | undefined {
96+
switch (data) {
97+
case rpc.RpcRetryOptions.RetryStrategy.exponential_backoff:
98+
return 'exponentialBackoff';
99+
case rpc.RpcRetryOptions.RetryStrategy.fixed_delay:
100+
return 'fixedDelay';
101+
default:
102+
return handleDefaultEnumCase(data, 'RpcRetryStrategy');
103+
}
104+
}

types-core/index.d.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ declare module '@azure/functions-core' {
2222
function registerFunction(metadata: FunctionMetadata, callback: FunctionCallback): Disposable;
2323

2424
/**
25-
* A slimmed down version of `RpcFunctionMetadata` that includes the minimum amount of information needed to register a function
25+
* A slimmed down version of `RpcFunctionMetadata` that includes only the properties respected as a part of the `registerFunction` api
2626
* 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
2727
*/
2828
interface FunctionMetadata {
@@ -43,6 +43,11 @@ declare module '@azure/functions-core' {
4343
* A dictionary of binding name to binding info
4444
*/
4545
bindings: { [name: string]: RpcBindingInfo };
46+
47+
/**
48+
* The retry policy options
49+
*/
50+
retryOptions?: RpcRetryOptions;
4651
}
4752

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

300305
managedDependencyEnabled?: boolean | null;
306+
307+
retryOptions?: RpcRetryOptions | null;
301308
}
302309

303310
interface RpcStatusResult {
@@ -352,6 +359,20 @@ declare module '@azure/functions-core' {
352359

353360
type RpcBindingDataType = 'undefined' | 'string' | 'binary' | 'stream';
354361

362+
interface RpcRetryOptions {
363+
maxRetryCount?: number | null;
364+
365+
delayInterval?: RpcDuration | null;
366+
367+
minimumInterval?: RpcDuration | null;
368+
369+
maximumInterval?: RpcDuration | null;
370+
371+
retryStrategy?: RpcRetryStrategy | null;
372+
}
373+
374+
type RpcRetryStrategy = 'exponentialBackoff' | 'fixedDelay';
375+
355376
interface RpcTypedData {
356377
string?: string | null;
357378

@@ -508,6 +529,12 @@ declare module '@azure/functions-core' {
508529
nanos?: number | null;
509530
}
510531

532+
interface RpcDuration {
533+
seconds?: number | Long | null;
534+
535+
nanos?: number | null;
536+
}
537+
511538
type RpcHttpCookieSameSite = 'none' | 'lax' | 'strict' | 'explicitNone';
512539
// #endregion rpc types
513540
}

0 commit comments

Comments
 (0)