@@ -194,8 +194,23 @@ impl Service for BoxedService {
194
194
/// Various configuration options that can be provided when binding a service
195
195
#[ derive( Default , Debug , Clone ) ]
196
196
pub struct ServiceOptions {
197
- /// Custom metadata of this service definition. This metadata is shown on the Admin API when querying the service definition.
198
- pub metadata : HashMap < String , String > ,
197
+ pub ( crate ) metadata : HashMap < String , String > ,
198
+ pub ( crate ) inactivity_timeout : Option < Duration > ,
199
+ pub ( crate ) abort_timeout : Option < Duration > ,
200
+ pub ( crate ) idempotency_retention : Option < Duration > ,
201
+ pub ( crate ) journal_retention : Option < Duration > ,
202
+ pub ( crate ) enable_lazy_state : Option < bool > ,
203
+ pub ( crate ) ingress_private : Option < bool > ,
204
+ pub ( crate ) handler_options : HashMap < String , HandlerOptions > ,
205
+
206
+ _priv : ( )
207
+ }
208
+
209
+ impl ServiceOptions {
210
+ pub fn new ( ) -> Self {
211
+ Self :: default ( )
212
+ }
213
+
199
214
/// This timer guards against stalled invocations. Once it expires, Restate triggers a graceful
200
215
/// termination by asking the invocation to suspend (which preserves intermediate progress).
201
216
///
@@ -204,7 +219,11 @@ pub struct ServiceOptions {
204
219
///
205
220
/// This overrides the default inactivity timeout configured in the restate-server for all
206
221
/// invocations to this service.
207
- pub inactivity_timeout : Option < Duration > ,
222
+ pub fn inactivity_timeout ( mut self , timeout : Duration ) -> Self {
223
+ self . inactivity_timeout = Some ( timeout) ;
224
+ self
225
+ }
226
+
208
227
/// This timer guards against stalled service/handler invocations that are supposed to terminate. The
209
228
/// abort timeout is started after the inactivity_timeout has expired and the service/handler
210
229
/// invocation has been asked to gracefully terminate. Once the timer expires, it will abort the
@@ -215,39 +234,93 @@ pub struct ServiceOptions {
215
234
///
216
235
/// This overrides the default abort timeout configured in the restate-server for all invocations to
217
236
/// this service.
218
- pub abort_timeout : Option < Duration > ,
237
+ pub fn abort_timeout ( mut self , timeout : Duration ) -> Self {
238
+ self . abort_timeout = Some ( timeout) ;
239
+ self
240
+ }
241
+
219
242
/// The retention duration of idempotent requests to this service.
220
- pub idempotency_retention : Option < Duration > ,
243
+ pub fn idempotency_retention ( mut self , retention : Duration ) -> Self {
244
+ self . idempotency_retention = Some ( retention) ;
245
+ self
246
+ }
247
+
221
248
/// The journal retention. When set, this applies to all requests to all handlers of this service.
222
249
///
223
250
/// In case the request has an idempotency key, the idempotency_retention caps the journal retention
224
251
/// time.
225
- pub journal_retention : Option < Duration > ,
252
+ pub fn journal_retention ( mut self , retention : Duration ) -> Self {
253
+ self . journal_retention = Some ( retention) ;
254
+ self
255
+ }
256
+
226
257
/// When set to `true`, lazy state will be enabled for all invocations to this service. This is
227
258
/// relevant only for workflows and virtual objects.
228
- pub enable_lazy_state : Option < bool > ,
259
+ pub fn enable_lazy_state ( mut self , enable : bool ) -> Self {
260
+ self . enable_lazy_state = Some ( enable) ;
261
+ self
262
+ }
263
+
229
264
/// When set to `true` this service, with all its handlers, cannot be invoked from the restate-server
230
265
/// HTTP and Kafka ingress, but only from other services.
231
- pub ingress_private : Option < bool > ,
266
+ pub fn ingress_private ( mut self , private : bool ) -> Self {
267
+ self . ingress_private = Some ( private) ;
268
+ self
269
+ }
270
+
271
+ /// Custom metadata of this service definition. This metadata is shown on the Admin API when querying the service definition.
272
+ pub fn metadata ( mut self , key : impl Into < String > , value : impl Into < String > ) -> Self {
273
+ self . metadata . insert ( key. into ( ) , value. into ( ) ) ;
274
+ self
275
+ }
276
+
232
277
/// Handler-specific options.
233
278
///
234
279
/// *Note*: If you provide a handler name for a non-existing handler, binding the service will *panic!*.
235
- pub handler_options : HashMap < String , HandlerOptions > ,
280
+ pub fn handler ( mut self , handler_name : impl Into < String > , options : HandlerOptions ) -> Self {
281
+ self . handler_options . insert ( handler_name. into ( ) , options) ;
282
+ self
283
+ }
236
284
}
237
285
238
286
/// Various configuration options that can be provided when binding a service handler
239
287
#[ derive( Default , Debug , Clone ) ]
240
288
pub struct HandlerOptions {
289
+ pub ( crate ) metadata : HashMap < String , String > ,
290
+ pub ( crate ) inactivity_timeout : Option < Duration > ,
291
+ pub ( crate ) abort_timeout : Option < Duration > ,
292
+ pub ( crate ) idempotency_retention : Option < Duration > ,
293
+ pub ( crate ) workflow_retention : Option < Duration > ,
294
+ pub ( crate ) journal_retention : Option < Duration > ,
295
+ pub ( crate ) ingress_private : Option < bool > ,
296
+ pub ( crate ) enable_lazy_state : Option < bool > ,
297
+
298
+ _priv : ( )
299
+ }
300
+
301
+ impl HandlerOptions {
302
+ pub fn new ( ) -> Self {
303
+ Self :: default ( )
304
+ }
305
+
241
306
/// Custom metadata of this handler definition. This metadata is shown on the Admin API when querying the service/handler definition.
242
- pub metadata : HashMap < String , String > ,
307
+ pub fn metadata ( mut self , key : impl Into < String > , value : impl Into < String > ) -> Self {
308
+ self . metadata . insert ( key. into ( ) , value. into ( ) ) ;
309
+ self
310
+ }
311
+
243
312
/// This timer guards against stalled invocations. Once it expires, Restate triggers a graceful
244
313
/// termination by asking the invocation to suspend (which preserves intermediate progress).
245
314
///
246
315
/// The abort_timeout is used to abort the invocation, in case it doesn't react to the request to
247
316
/// suspend.
248
317
///
249
318
/// This overrides the inactivity timeout set for the service and the default set in restate-server.
250
- pub inactivity_timeout : Option < Duration > ,
319
+ pub fn inactivity_timeout ( mut self , timeout : Duration ) -> Self {
320
+ self . inactivity_timeout = Some ( timeout) ;
321
+ self
322
+ }
323
+
251
324
/// This timer guards against stalled invocations that are supposed to terminate. The abort timeout
252
325
/// is started after the inactivity_timeout has expired and the invocation has been asked to
253
326
/// gracefully terminate. Once the timer expires, it will abort the invocation.
@@ -256,22 +329,45 @@ pub struct HandlerOptions {
256
329
/// terminate, then this value needs to be set accordingly.
257
330
///
258
331
/// This overrides the abort timeout set for the service and the default set in restate-server.
259
- pub abort_timeout : Option < Duration > ,
332
+ pub fn abort_timeout ( mut self , timeout : Duration ) -> Self {
333
+ self . abort_timeout = Some ( timeout) ;
334
+ self
335
+ }
336
+
260
337
/// The retention duration of idempotent requests to this service.
261
- pub idempotency_retention : Option < Duration > ,
338
+ pub fn idempotency_retention ( mut self , retention : Duration ) -> Self {
339
+ self . idempotency_retention = Some ( retention) ;
340
+ self
341
+ }
342
+
262
343
/// The retention duration for this workflow handler.
263
- pub workflow_retention : Option < Duration > ,
344
+ pub fn workflow_retention ( mut self , retention : Duration ) -> Self {
345
+ self . workflow_retention = Some ( retention) ;
346
+ self
347
+ }
348
+
264
349
/// The journal retention for invocations to this handler.
265
350
///
266
351
/// In case the request has an idempotency key, the idempotency_retention caps the journal retention
267
352
/// time.
268
- pub journal_retention : Option < Duration > ,
353
+ pub fn journal_retention ( mut self , retention : Duration ) -> Self {
354
+ self . journal_retention = Some ( retention) ;
355
+ self
356
+ }
357
+
269
358
/// When set to `true` this handler cannot be invoked from the restate-server HTTP and Kafka ingress,
270
359
/// but only from other services.
271
- pub ingress_private : Option < bool > ,
360
+ pub fn ingress_private ( mut self , private : bool ) -> Self {
361
+ self . ingress_private = Some ( private) ;
362
+ self
363
+ }
364
+
272
365
/// When set to `true`, lazy state will be enabled for all invocations to this handler. This is
273
366
/// relevant only for workflows and virtual objects.
274
- pub enable_lazy_state : Option < bool > ,
367
+ pub fn enable_lazy_state ( mut self , enable : bool ) -> Self {
368
+ self . enable_lazy_state = Some ( enable) ;
369
+ self
370
+ }
275
371
}
276
372
277
373
/// Builder for [`Endpoint`]
0 commit comments