Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions packages/restate-sdk-examples/src/greeter_with_options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,10 @@ serve({
defaultServiceOptions: {
// You can configure default service options that will be applied to every service.
journalRetention: { days: 10 },
retryPolicy: {
initialInterval: { milliseconds: 100 },
onMaxAttempts: "pause",
maxAttempts: 10,
},
},
});
1 change: 1 addition & 0 deletions packages/restate-sdk-testcontainers/src/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ export type {
TerminalError,
RestateError,
EndpointOptions,
RetryPolicy,
} from "@restatedev/restate-sdk";
1 change: 1 addition & 0 deletions packages/restate-sdk/src/common_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export type {
ServiceOptions,
ObjectOptions,
WorkflowOptions,
RetryPolicy,
} from "./types/rpc.js";
export {
service,
Expand Down
33 changes: 32 additions & 1 deletion packages/restate-sdk/src/endpoint/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ export function parseUrlComponents(urlPath?: string): PathComponents {

function commonServiceOptions(
options?: ServiceOptions | ObjectOptions | WorkflowOptions
) {
): Partial<d.Service> {
return {
journalRetention:
options?.journalRetention !== undefined
Expand All @@ -364,6 +364,21 @@ function commonServiceOptions(
options !== undefined && "enableLazyState" in options
? options.enableLazyState
: undefined,
retryPolicyExponentiationFactor: options?.retryPolicy?.exponentiationFactor,
retryPolicyInitialInterval:
options?.retryPolicy?.initialInterval !== undefined
? millisOrDurationToMillis(options?.retryPolicy?.initialInterval)
: undefined,
retryPolicyMaxInterval:
options?.retryPolicy?.maxInterval !== undefined
? millisOrDurationToMillis(options?.retryPolicy?.maxInterval)
: undefined,
retryPolicyMaxAttempts: options?.retryPolicy?.maxAttempts,
retryPolicyOnMaxAttempts: (options?.retryPolicy?.onMaxAttempts === "kill"
? "KILL"
: options?.retryPolicy?.onMaxAttempts === "pause"
? "PAUSE"
: undefined) as d.RetryPolicyOnMaxAttempts,
};
}

Expand All @@ -389,6 +404,22 @@ function commonHandlerOptions(wrapper: HandlerWrapper) {
: undefined,
ingressPrivate: wrapper.ingressPrivate,
enableLazyState: wrapper.enableLazyState,
retryPolicyExponentiationFactor: wrapper.retryPolicy?.exponentiationFactor,
retryPolicyInitialInterval:
wrapper.retryPolicy?.initialInterval !== undefined
? millisOrDurationToMillis(wrapper.retryPolicy?.initialInterval)
: undefined,
retryPolicyMaxInterval:
wrapper.retryPolicy?.maxInterval !== undefined
? millisOrDurationToMillis(wrapper.retryPolicy?.maxInterval)
: undefined,
retryPolicyMaxAttempts: wrapper.retryPolicy?.maxAttempts,
retryPolicyOnMaxAttempts: (wrapper.retryPolicy?.onMaxAttempts === "kill"
? "KILL"
: wrapper.retryPolicy?.onMaxAttempts === "pause"
? "PAUSE"
: undefined) as d.RetryPolicyOnMaxAttempts1,

documentation: wrapper.description,
metadata: wrapper.metadata,
};
Expand Down
42 changes: 42 additions & 0 deletions packages/restate-sdk/src/endpoint/discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ export type ServiceType = "VIRTUAL_OBJECT" | "SERVICE" | "WORKFLOW";
* If unspecified, defaults to EXCLUSIVE for Virtual Object or WORKFLOW for Workflows. This should be unset for Services.
*/
export type HandlerType = "WORKFLOW" | "EXCLUSIVE" | "SHARED";
/**
* Retry policy behavior on max attempts.
*/
export type RetryPolicyOnMaxAttempts = "PAUSE" | "KILL";
/**
* Retry policy behavior on max attempts.
*/
export type RetryPolicyOnMaxAttempts1 = "PAUSE" | "KILL";

/**
* Restate endpoint manifest v3
Expand Down Expand Up @@ -63,6 +71,23 @@ export interface Service {
* If true, the service cannot be invoked from the HTTP nor Kafka ingress.
*/
ingressPrivate?: boolean;
/**
* Retry policy initial interval, expressed in milliseconds.
*/
retryPolicyInitialInterval?: number;
/**
* Retry policy max interval, expressed in milliseconds.
*/
retryPolicyMaxInterval?: number;
/**
* Retry policy max attempts.
*/
retryPolicyMaxAttempts?: number;
/**
* Retry policy exponentiation factor.
*/
retryPolicyExponentiationFactor?: number;
retryPolicyOnMaxAttempts?: RetryPolicyOnMaxAttempts1;
/**
* Custom metadata of this service definition. This metadata is shown on the Admin API when querying the service definition.
*/
Expand Down Expand Up @@ -107,6 +132,23 @@ export interface Handler {
* If true, the service cannot be invoked from the HTTP nor Kafka ingress.
*/
ingressPrivate?: boolean;
/**
* Retry policy initial interval, expressed in milliseconds.
*/
retryPolicyInitialInterval?: number;
/**
* Retry policy max interval, expressed in milliseconds.
*/
retryPolicyMaxInterval?: number;
/**
* Retry policy max attempts.
*/
retryPolicyMaxAttempts?: number;
/**
* Retry policy exponentiation factor.
*/
retryPolicyExponentiationFactor?: number;
retryPolicyOnMaxAttempts?: RetryPolicyOnMaxAttempts;
/**
* Custom metadata of this handler definition. This metadata is shown on the Admin API when querying the service/handler definition.
*/
Expand Down
26 changes: 26 additions & 0 deletions packages/restate-sdk/src/endpoint/handlers/generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,32 @@ export class GenericHandler implements RestateHandler {
if (manifestVersion < 4) {
// Blank the lambda compression field. No need to fail in this case.
discovery.lambdaCompression = undefined;
for (const service of discovery.services) {
const error = checkUnsupportedFeature(
service,
"retryPolicyExponentiationFactor",
"retryPolicyInitialInterval",
"retryPolicyMaxAttempts",
"retryPolicyMaxInterval",
"retryPolicyOnMaxAttempts"
);
if (error !== undefined) {
return error;
}
for (const handler of service.handlers) {
const error = checkUnsupportedFeature(
handler,
"retryPolicyExponentiationFactor",
"retryPolicyInitialInterval",
"retryPolicyMaxAttempts",
"retryPolicyMaxInterval",
"retryPolicyOnMaxAttempts"
);
if (error !== undefined) {
return error;
}
}
}
}

const body = JSON.stringify(discovery);
Expand Down
Loading