@@ -60,8 +60,26 @@ def __init__(self, setContentTypeIfEmpty: bool, contentType: Optional[str] = Non
60
60
self .jsonSchema = jsonSchema
61
61
62
62
class Handler :
63
- # pylint: disable=R0902
64
- def __init__ (self , name : str , ty : Optional [ServiceHandlerType ] = None , input : Optional [InputPayload | Dict [str , str ]] = None , output : Optional [OutputPayload ] = None , description : Optional [str ] = None , metadata : Optional [Dict [str , str ]] = None , inactivityTimeout : Optional [int ] = None , abortTimeout : Optional [int ] = None , journalRetention : Optional [int ] = None , idempotencyRetention : Optional [int ] = None , workflowCompletionRetention : Optional [int ] = None , enableLazyState : Optional [bool ] = None , ingressPrivate : Optional [bool ] = None ):
63
+ # pylint: disable=R0902,R0914
64
+ def __init__ (self ,
65
+ name : str ,
66
+ ty : Optional [ServiceHandlerType ] = None ,
67
+ input : Optional [InputPayload | Dict [str , str ]] = None ,
68
+ output : Optional [OutputPayload ] = None ,
69
+ description : Optional [str ] = None ,
70
+ metadata : Optional [Dict [str , str ]] = None ,
71
+ inactivityTimeout : Optional [int ] = None ,
72
+ abortTimeout : Optional [int ] = None ,
73
+ journalRetention : Optional [int ] = None ,
74
+ idempotencyRetention : Optional [int ] = None ,
75
+ workflowCompletionRetention : Optional [int ] = None ,
76
+ enableLazyState : Optional [bool ] = None ,
77
+ ingressPrivate : Optional [bool ] = None ,
78
+ retryPolicyInitialInterval : Optional [int ] = None ,
79
+ retryPolicyMaxInterval : Optional [int ] = None ,
80
+ retryPolicyMaxAttempts : Optional [int ] = None ,
81
+ retryPolicyExponentiationFactor : Optional [float ] = None ,
82
+ retryPolicyOnMaxAttempts : Optional [str ] = None ):
65
83
self .name = name
66
84
self .ty = ty
67
85
self .input = input
@@ -75,10 +93,31 @@ def __init__(self, name: str, ty: Optional[ServiceHandlerType] = None, input: Op
75
93
self .workflowCompletionRetention = workflowCompletionRetention
76
94
self .enableLazyState = enableLazyState
77
95
self .ingressPrivate = ingressPrivate
96
+ self .retryPolicyInitialInterval = retryPolicyInitialInterval
97
+ self .retryPolicyMaxInterval = retryPolicyMaxInterval
98
+ self .retryPolicyMaxAttempts = retryPolicyMaxAttempts
99
+ self .retryPolicyExponentiationFactor = retryPolicyExponentiationFactor
100
+ self .retryPolicyOnMaxAttempts = retryPolicyOnMaxAttempts
78
101
79
102
class Service :
80
- # pylint: disable=R0902
81
- def __init__ (self , name : str , ty : ServiceType , handlers : List [Handler ], description : Optional [str ] = None , metadata : Optional [Dict [str , str ]] = None , inactivityTimeout : Optional [int ] = None , abortTimeout : Optional [int ] = None , journalRetention : Optional [int ] = None , idempotencyRetention : Optional [int ] = None , enableLazyState : Optional [bool ] = None , ingressPrivate : Optional [bool ] = None ):
103
+ # pylint: disable=R0902,R0914
104
+ def __init__ (self ,
105
+ name : str ,
106
+ ty : ServiceType ,
107
+ handlers : List [Handler ],
108
+ description : Optional [str ] = None ,
109
+ metadata : Optional [Dict [str , str ]] = None ,
110
+ inactivityTimeout : Optional [int ] = None ,
111
+ abortTimeout : Optional [int ] = None ,
112
+ journalRetention : Optional [int ] = None ,
113
+ idempotencyRetention : Optional [int ] = None ,
114
+ enableLazyState : Optional [bool ] = None ,
115
+ ingressPrivate : Optional [bool ] = None ,
116
+ retryPolicyInitialInterval : Optional [int ] = None ,
117
+ retryPolicyMaxInterval : Optional [int ] = None ,
118
+ retryPolicyMaxAttempts : Optional [int ] = None ,
119
+ retryPolicyExponentiationFactor : Optional [float ] = None ,
120
+ retryPolicyOnMaxAttempts : Optional [str ] = None ):
82
121
self .name = name
83
122
self .ty = ty
84
123
self .handlers = handlers
@@ -90,6 +129,11 @@ def __init__(self, name: str, ty: ServiceType, handlers: List[Handler], descript
90
129
self .idempotencyRetention = idempotencyRetention
91
130
self .enableLazyState = enableLazyState
92
131
self .ingressPrivate = ingressPrivate
132
+ self .retryPolicyInitialInterval = retryPolicyInitialInterval
133
+ self .retryPolicyMaxInterval = retryPolicyMaxInterval
134
+ self .retryPolicyMaxAttempts = retryPolicyMaxAttempts
135
+ self .retryPolicyExponentiationFactor = retryPolicyExponentiationFactor
136
+ self .retryPolicyOnMaxAttempts = retryPolicyOnMaxAttempts
93
137
94
138
class Endpoint :
95
139
def __init__ (self , protocolMode : ProtocolMode , minProtocolVersion : int , maxProtocolVersion : int , services : List [Service ]):
@@ -163,7 +207,7 @@ def json_schema_from_type_hint(type_hint: Optional[TypeHint[Any]]) -> Any:
163
207
return type_hint_to_json_schema (type_hint .annotation )
164
208
165
209
166
- # pylint: disable=R0912
210
+ # pylint: disable=R0912,R0915
167
211
def compute_discovery_json (endpoint : RestateEndpoint ,
168
212
version : int ,
169
213
discovered_as : typing .Literal ["bidi" , "request_response" ]) -> str :
@@ -174,6 +218,31 @@ def compute_discovery_json(endpoint: RestateEndpoint,
174
218
ep = compute_discovery (endpoint , discovered_as )
175
219
176
220
# Validate that new discovery fields aren't used with older protocol versions
221
+ if version <= 3 :
222
+ for service in ep .services :
223
+ if service .retryPolicyInitialInterval is not None :
224
+ raise ValueError ("retryPolicyInitialInterval is only supported in discovery protocol version 4" )
225
+ if service .retryPolicyMaxInterval is not None :
226
+ raise ValueError ("retryPolicyMaxInterval is only supported in discovery protocol version 4" )
227
+ if service .retryPolicyMaxAttempts is not None :
228
+ raise ValueError ("retryPolicyMaxAttempts is only supported in discovery protocol version 4" )
229
+ if service .retryPolicyExponentiationFactor is not None :
230
+ raise ValueError ("retryPolicyExponentiationFactor is only supported in discovery protocol version 4" )
231
+ if service .retryPolicyOnMaxAttempts is not None :
232
+ raise ValueError ("retryPolicyOnMaxAttempts is only supported in discovery protocol version 4" )
233
+
234
+ for handler in service .handlers :
235
+ if handler .retryPolicyInitialInterval is not None :
236
+ raise ValueError ("retryPolicyInitialInterval is only supported in discovery protocol version 4" )
237
+ if handler .retryPolicyMaxInterval is not None :
238
+ raise ValueError ("retryPolicyMaxInterval is only supported in discovery protocol version 4" )
239
+ if handler .retryPolicyMaxAttempts is not None :
240
+ raise ValueError ("retryPolicyMaxAttempts is only supported in discovery protocol version 4" )
241
+ if handler .retryPolicyExponentiationFactor is not None :
242
+ raise ValueError ("retryPolicyExponentiationFactor is only supported in discovery protocol version 4" )
243
+ if handler .retryPolicyOnMaxAttempts is not None :
244
+ raise ValueError ("retryPolicyOnMaxAttempts is only supported in discovery protocol version 4" )
245
+
177
246
if version <= 2 :
178
247
# Check for new discovery fields in version 3 that shouldn't be used in version 2 or lower
179
248
for service in ep .services :
@@ -253,21 +322,31 @@ def compute_discovery(endpoint: RestateEndpoint, discovered_as : typing.Literal[
253
322
idempotencyRetention = int (handler .idempotency_retention .total_seconds () * 1000 ) if handler .idempotency_retention else None ,
254
323
workflowCompletionRetention = int (handler .workflow_retention .total_seconds () * 1000 ) if handler .workflow_retention else None ,
255
324
enableLazyState = handler .enable_lazy_state ,
256
- ingressPrivate = handler .ingress_private ))
325
+ ingressPrivate = handler .ingress_private ,
326
+ retryPolicyInitialInterval = int (handler .invocation_retry_policy .initial_interval .total_seconds () * 1000 ) if handler .invocation_retry_policy and handler .invocation_retry_policy .initial_interval else None ,
327
+ retryPolicyMaxInterval = int (handler .invocation_retry_policy .max_interval .total_seconds () * 1000 ) if handler .invocation_retry_policy and handler .invocation_retry_policy .max_interval else None ,
328
+ retryPolicyMaxAttempts = int (handler .invocation_retry_policy .max_attempts ) if handler .invocation_retry_policy and handler .invocation_retry_policy .max_attempts is not None else None ,
329
+ retryPolicyExponentiationFactor = float (handler .invocation_retry_policy .exponentiation_factor ) if handler .invocation_retry_policy and handler .invocation_retry_policy .exponentiation_factor is not None else None ,
330
+ retryPolicyOnMaxAttempts = (handler .invocation_retry_policy .on_max_attempts .upper () if handler .invocation_retry_policy and handler .invocation_retry_policy .on_max_attempts is not None else None )))
257
331
# add the service
258
332
description = service .service_tag .description
259
333
metadata = service .service_tag .metadata
260
334
services .append (Service (name = service .name ,
261
- ty = service_type ,
262
- handlers = service_handlers ,
263
- description = description ,
264
- metadata = metadata ,
265
- inactivityTimeout = int (service .inactivity_timeout .total_seconds () * 1000 ) if service .inactivity_timeout else None ,
266
- abortTimeout = int (service .abort_timeout .total_seconds () * 1000 ) if service .abort_timeout else None ,
267
- journalRetention = int (service .journal_retention .total_seconds () * 1000 ) if service .journal_retention else None ,
268
- idempotencyRetention = int (service .idempotency_retention .total_seconds () * 1000 ) if service .idempotency_retention else None ,
269
- enableLazyState = service .enable_lazy_state if hasattr (service , 'enable_lazy_state' ) else None ,
270
- ingressPrivate = service .ingress_private ))
335
+ ty = service_type ,
336
+ handlers = service_handlers ,
337
+ description = description ,
338
+ metadata = metadata ,
339
+ inactivityTimeout = int (service .inactivity_timeout .total_seconds () * 1000 ) if service .inactivity_timeout else None ,
340
+ abortTimeout = int (service .abort_timeout .total_seconds () * 1000 ) if service .abort_timeout else None ,
341
+ journalRetention = int (service .journal_retention .total_seconds () * 1000 ) if service .journal_retention else None ,
342
+ idempotencyRetention = int (service .idempotency_retention .total_seconds () * 1000 ) if service .idempotency_retention else None ,
343
+ enableLazyState = service .enable_lazy_state if hasattr (service , 'enable_lazy_state' ) else None ,
344
+ ingressPrivate = service .ingress_private ,
345
+ retryPolicyInitialInterval = int (service .invocation_retry_policy .initial_interval .total_seconds () * 1000 ) if service .invocation_retry_policy and service .invocation_retry_policy .initial_interval else None ,
346
+ retryPolicyMaxInterval = int (service .invocation_retry_policy .max_interval .total_seconds () * 1000 ) if service .invocation_retry_policy and service .invocation_retry_policy .max_interval else None ,
347
+ retryPolicyMaxAttempts = int (service .invocation_retry_policy .max_attempts ) if service .invocation_retry_policy and service .invocation_retry_policy .max_attempts is not None else None ,
348
+ retryPolicyExponentiationFactor = float (service .invocation_retry_policy .exponentiation_factor ) if service .invocation_retry_policy and service .invocation_retry_policy .exponentiation_factor is not None else None ,
349
+ retryPolicyOnMaxAttempts = (service .invocation_retry_policy .on_max_attempts .upper () if service .invocation_retry_policy and service .invocation_retry_policy .on_max_attempts is not None else None )))
271
350
272
351
if endpoint .protocol :
273
352
protocol_mode = PROTOCOL_MODES [endpoint .protocol ]
0 commit comments