Skip to content

Commit e7b8ff6

Browse files
Add workflow retention setting at service level (#547)
1 parent 07290f2 commit e7b8ff6

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

examples/src/main/java/my/restate/sdk/examples/LoanWorkflow.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ public Status getStatus(SharedWorkflowContext ctx) {
121121
}
122122

123123
public static void main(String[] args) {
124-
Endpoint endpoint = Endpoint.builder().bind(new LoanWorkflow()).bind(new MockBank()).build();
124+
Endpoint endpoint =
125+
Endpoint.builder()
126+
.bind(new LoanWorkflow(), c -> c.workflowRetention(Duration.ofDays(10)))
127+
.bind(new MockBank())
128+
.build();
125129

126130
RestateHttpServer.listen(endpoint);
127131

sdk-api-kotlin/src/main/kotlin/dev/restate/sdk/kotlin/endpoint/endpoint.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@ var ServiceDefinition.Configurator.abortTimeout: Duration?
8888
this.abortTimeout(value?.toJavaDuration())
8989
}
9090

91+
/**
92+
* The retention duration for this workflow. This applies only to workflow services.
93+
*
94+
* *NOTE:* You can set this field only if you register this service against restate-server >= 1.4,
95+
* otherwise the service discovery will fail.
96+
*/
97+
var ServiceDefinition.Configurator.workflowRetention: Duration?
98+
get() {
99+
return this.workflowRetention()?.toKotlinDuration()
100+
}
101+
set(value) {
102+
this.workflowRetention(value?.toJavaDuration())
103+
}
104+
91105
/**
92106
* The retention duration of idempotent requests to this service.
93107
*

sdk-common/src/main/java/dev/restate/sdk/endpoint/definition/ServiceDefinition.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,43 @@ public Configurator abortTimeout(@Nullable Duration abortTimeout) {
362362
return this;
363363
}
364364

365+
/**
366+
* @return configured workflow retention.
367+
* @see #workflowRetention(Duration)
368+
*/
369+
public @Nullable Duration workflowRetention() {
370+
return handlers.values().stream()
371+
.filter(h -> h.getHandlerType() == HandlerType.WORKFLOW)
372+
.findFirst()
373+
.orElseThrow(
374+
() ->
375+
new IllegalArgumentException(
376+
"Workflow retention cannot be set for non-workflow services"))
377+
.getWorkflowRetention();
378+
}
379+
380+
/**
381+
* The retention duration of idempotent requests to this workflow service. This applies only to
382+
* workflow services.
383+
*
384+
* <p><b>NOTE:</b> You can set this field only if you register this service against
385+
* restate-server >= 1.4, otherwise the service discovery will fail.
386+
*
387+
* @return this
388+
*/
389+
public Configurator workflowRetention(@Nullable Duration workflowRetention) {
390+
String workflowHandlerName =
391+
handlers.entrySet().stream()
392+
.filter(e -> e.getValue().getHandlerType() == HandlerType.WORKFLOW)
393+
.findFirst()
394+
.orElseThrow(
395+
() ->
396+
new IllegalArgumentException(
397+
"Workflow retention cannot be set for non-workflow services"))
398+
.getKey();
399+
return configureHandler(workflowHandlerName, ch -> ch.workflowRetention(workflowRetention));
400+
}
401+
365402
/**
366403
* @return configured idempotency retention.
367404
* @see #idempotencyRetention(Duration)

0 commit comments

Comments
 (0)