@@ -60,21 +60,36 @@ def __init__(self, setContentTypeIfEmpty: bool, contentType: Optional[str] = Non
60
60
self .jsonSchema = jsonSchema
61
61
62
62
class Handler :
63
- 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 ):
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 ):
64
65
self .name = name
65
66
self .ty = ty
66
67
self .input = input
67
68
self .output = output
68
69
self .documentation = description
69
70
self .metadata = metadata
71
+ self .inactivityTimeout = inactivityTimeout
72
+ self .abortTimeout = abortTimeout
73
+ self .journalRetention = journalRetention
74
+ self .idempotencyRetention = idempotencyRetention
75
+ self .workflowCompletionRetention = workflowCompletionRetention
76
+ self .enableLazyState = enableLazyState
77
+ self .ingressPrivate = ingressPrivate
70
78
71
79
class Service :
72
- def __init__ (self , name : str , ty : ServiceType , handlers : List [Handler ], description : Optional [str ] = None , metadata : Optional [Dict [str , str ]] = None ):
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 ):
73
82
self .name = name
74
83
self .ty = ty
75
84
self .handlers = handlers
76
85
self .documentation = description
77
86
self .metadata = metadata
87
+ self .inactivityTimeout = inactivityTimeout
88
+ self .abortTimeout = abortTimeout
89
+ self .journalRetention = journalRetention
90
+ self .idempotencyRetention = idempotencyRetention
91
+ self .enableLazyState = enableLazyState
92
+ self .ingressPrivate = ingressPrivate
78
93
79
94
class Endpoint :
80
95
def __init__ (self , protocolMode : ProtocolMode , minProtocolVersion : int , maxProtocolVersion : int , services : List [Service ]):
@@ -148,20 +163,51 @@ def json_schema_from_type_hint(type_hint: Optional[TypeHint[Any]]) -> Any:
148
163
return type_hint_to_json_schema (type_hint .annotation )
149
164
150
165
151
-
166
+ # pylint: disable=R0912
152
167
def compute_discovery_json (endpoint : RestateEndpoint ,
153
168
version : int ,
154
- discovered_as : typing .Literal ["bidi" , "request_response" ]) -> typing . Tuple [ typing . Dict [ str , str ] , str ] :
169
+ discovered_as : typing .Literal ["bidi" , "request_response" ]) -> str :
155
170
"""
156
- return restate's discovery object as JSON
171
+ return restate's discovery object as JSON
157
172
"""
158
- if version != 1 :
159
- raise ValueError (f"Unsupported protocol version { version } " )
160
173
161
174
ep = compute_discovery (endpoint , discovered_as )
175
+
176
+ # Validate that new discovery fields aren't used with older protocol versions
177
+ if version <= 2 :
178
+ # Check for new discovery fields in version 3 that shouldn't be used in version 2 or lower
179
+ for service in ep .services :
180
+ if service .inactivityTimeout is not None :
181
+ raise ValueError ("inactivityTimeout is only supported in discovery protocol version 3" )
182
+ if service .abortTimeout is not None :
183
+ raise ValueError ("abortTimeout is only supported in discovery protocol version 3" )
184
+ if service .idempotencyRetention is not None :
185
+ raise ValueError ("idempotencyRetention is only supported in discovery protocol version 3" )
186
+ if service .journalRetention is not None :
187
+ raise ValueError ("journalRetention is only supported in discovery protocol version 3" )
188
+ if service .enableLazyState is not None :
189
+ raise ValueError ("enableLazyState is only supported in discovery protocol version 3" )
190
+ if service .ingressPrivate is not None :
191
+ raise ValueError ("ingressPrivate is only supported in discovery protocol version 3" )
192
+
193
+ for handler in service .handlers :
194
+ if handler .inactivityTimeout is not None :
195
+ raise ValueError ("inactivityTimeout is only supported in discovery protocol version 3" )
196
+ if handler .abortTimeout is not None :
197
+ raise ValueError ("abortTimeout is only supported in discovery protocol version 3" )
198
+ if handler .idempotencyRetention is not None :
199
+ raise ValueError ("idempotencyRetention is only supported in discovery protocol version 3" )
200
+ if handler .journalRetention is not None :
201
+ raise ValueError ("journalRetention is only supported in discovery protocol version 3" )
202
+ if handler .workflowCompletionRetention is not None :
203
+ raise ValueError ("workflowCompletionRetention is only supported in discovery protocol version 3" )
204
+ if handler .enableLazyState is not None :
205
+ raise ValueError ("enableLazyState is only supported in discovery protocol version 3" )
206
+ if handler .ingressPrivate is not None :
207
+ raise ValueError ("ingressPrivate is only supported in discovery protocol version 3" )
208
+
162
209
json_str = json .dumps (ep , cls = PythonClassEncoder , allow_nan = False )
163
- headers = {"content-type" : "application/vnd.restate.endpointmanifest.v1+json" }
164
- return (headers , json_str )
210
+ return json_str
165
211
166
212
167
213
def compute_discovery (endpoint : RestateEndpoint , discovered_as : typing .Literal ["bidi" , "request_response" ]) -> Endpoint :
@@ -200,11 +246,28 @@ def compute_discovery(endpoint: RestateEndpoint, discovered_as : typing.Literal[
200
246
input = inp ,
201
247
output = out ,
202
248
description = handler .description ,
203
- metadata = handler .metadata ))
249
+ metadata = handler .metadata ,
250
+ inactivityTimeout = int (handler .inactivity_timeout .total_seconds () * 1000 ) if handler .inactivity_timeout else None ,
251
+ abortTimeout = int (handler .abort_timeout .total_seconds () * 1000 ) if handler .abort_timeout else None ,
252
+ journalRetention = int (handler .journal_retention .total_seconds () * 1000 ) if handler .journal_retention else None ,
253
+ idempotencyRetention = int (handler .idempotency_retention .total_seconds () * 1000 ) if handler .idempotency_retention else None ,
254
+ workflowCompletionRetention = int (handler .workflow_retention .total_seconds () * 1000 ) if handler .workflow_retention else None ,
255
+ enableLazyState = handler .enable_lazy_state ,
256
+ ingressPrivate = handler .ingress_private ))
204
257
# add the service
205
258
description = service .service_tag .description
206
259
metadata = service .service_tag .metadata
207
- services .append (Service (name = service .name , ty = service_type , handlers = service_handlers , description = description , metadata = metadata ))
260
+ 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 ))
208
271
209
272
if endpoint .protocol :
210
273
protocol_mode = PROTOCOL_MODES [endpoint .protocol ]
0 commit comments