@@ -194,8 +194,23 @@ impl Service for BoxedService {
194194/// Various configuration options that can be provided when binding a service
195195#[ derive( Default , Debug , Clone ) ]
196196pub 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+
199214 /// This timer guards against stalled invocations. Once it expires, Restate triggers a graceful
200215 /// termination by asking the invocation to suspend (which preserves intermediate progress).
201216 ///
@@ -204,7 +219,11 @@ pub struct ServiceOptions {
204219 ///
205220 /// This overrides the default inactivity timeout configured in the restate-server for all
206221 /// 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+
208227 /// This timer guards against stalled service/handler invocations that are supposed to terminate. The
209228 /// abort timeout is started after the inactivity_timeout has expired and the service/handler
210229 /// invocation has been asked to gracefully terminate. Once the timer expires, it will abort the
@@ -215,39 +234,93 @@ pub struct ServiceOptions {
215234 ///
216235 /// This overrides the default abort timeout configured in the restate-server for all invocations to
217236 /// 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+
219242 /// 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+
221248 /// The journal retention. When set, this applies to all requests to all handlers of this service.
222249 ///
223250 /// In case the request has an idempotency key, the idempotency_retention caps the journal retention
224251 /// 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+
226257 /// When set to `true`, lazy state will be enabled for all invocations to this service. This is
227258 /// 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+
229264 /// When set to `true` this service, with all its handlers, cannot be invoked from the restate-server
230265 /// 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+
232277 /// Handler-specific options.
233278 ///
234279 /// *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+ }
236284}
237285
238286/// Various configuration options that can be provided when binding a service handler
239287#[ derive( Default , Debug , Clone ) ]
240288pub 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+
241306 /// 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+
243312 /// This timer guards against stalled invocations. Once it expires, Restate triggers a graceful
244313 /// termination by asking the invocation to suspend (which preserves intermediate progress).
245314 ///
246315 /// The abort_timeout is used to abort the invocation, in case it doesn't react to the request to
247316 /// suspend.
248317 ///
249318 /// 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+
251324 /// This timer guards against stalled invocations that are supposed to terminate. The abort timeout
252325 /// is started after the inactivity_timeout has expired and the invocation has been asked to
253326 /// gracefully terminate. Once the timer expires, it will abort the invocation.
@@ -256,22 +329,45 @@ pub struct HandlerOptions {
256329 /// terminate, then this value needs to be set accordingly.
257330 ///
258331 /// 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+
260337 /// 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+
262343 /// 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+
264349 /// The journal retention for invocations to this handler.
265350 ///
266351 /// In case the request has an idempotency key, the idempotency_retention caps the journal retention
267352 /// 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+
269358 /// When set to `true` this handler cannot be invoked from the restate-server HTTP and Kafka ingress,
270359 /// 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+
272365 /// When set to `true`, lazy state will be enabled for all invocations to this handler. This is
273366 /// 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+ }
275371}
276372
277373/// Builder for [`Endpoint`]
0 commit comments