Skip to content

Commit

Permalink
Add support to retrieve invocations from idempotency key. Fix #358 (#359
Browse files Browse the repository at this point in the history
)
  • Loading branch information
slinkydeveloper authored Jul 18, 2024
1 parent cd23a59 commit cf60abf
Show file tree
Hide file tree
Showing 3 changed files with 199 additions and 150 deletions.
12 changes: 12 additions & 0 deletions sdk-api-kotlin/src/main/kotlin/dev/restate/sdk/kotlin/ingress.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ suspend fun <T : Any?> Client.InvocationHandle<T>.getOutputSuspend(
return this.getOutputAsync(options).await()
}

suspend fun <T> Client.IdempotentInvocationHandle<T>.attachSuspend(
options: RequestOptions = RequestOptions.DEFAULT
): T {
return this.attachAsync(options).await()
}

suspend fun <T> Client.IdempotentInvocationHandle<T>.getOutputSuspend(
options: RequestOptions = RequestOptions.DEFAULT
): Output<T> {
return this.getOutputAsync(options).await()
}

suspend fun <T> Client.WorkflowHandle<T>.attachSuspend(
options: RequestOptions = RequestOptions.DEFAULT
): T {
Expand Down
48 changes: 48 additions & 0 deletions sdk-common/src/main/java/dev/restate/sdk/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,54 @@ default Output<Res> getOutput() throws IngressException {
}
}

<Res> IdempotentInvocationHandle<Res> idempotentInvocationHandle(
Target target, String idempotencyKey, Serde<Res> resSerde);

interface IdempotentInvocationHandle<Res> {

CompletableFuture<Res> attachAsync(RequestOptions options);

default CompletableFuture<Res> attachAsync() {
return attachAsync(RequestOptions.DEFAULT);
}

default Res attach(RequestOptions options) throws IngressException {
try {
return attachAsync(options).join();
} catch (CompletionException e) {
if (e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
}
throw new RuntimeException(e.getCause());
}
}

default Res attach() throws IngressException {
return attach(RequestOptions.DEFAULT);
}

CompletableFuture<Output<Res>> getOutputAsync(RequestOptions options);

default CompletableFuture<Output<Res>> getOutputAsync() {
return getOutputAsync(RequestOptions.DEFAULT);
}

default Output<Res> getOutput(RequestOptions options) throws IngressException {
try {
return getOutputAsync(options).join();
} catch (CompletionException e) {
if (e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
}
throw new RuntimeException(e.getCause());
}
}

default Output<Res> getOutput() throws IngressException {
return getOutput(RequestOptions.DEFAULT);
}
}

<Res> WorkflowHandle<Res> workflowHandle(
String workflowName, String workflowId, Serde<Res> resSerde);

Expand Down
Loading

0 comments on commit cf60abf

Please sign in to comment.