Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ingress awakeable resolve/reject #256

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ public <Req> CompletableFuture<String> sendAsync(
public AwakeableHandle awakeableHandle(String id) {
return new AwakeableHandle() {
@Override
public <T> CompletableFuture<Void> resolve(Serde<T> serde, @NonNull T payload) {
public <T> CompletableFuture<Void> resolveAsync(Serde<T> serde, @NonNull T payload) {
// Prepare request
var reqBuilder =
HttpRequest.newBuilder().uri(URI.create("/restate/awakeables/" + id + "/resolve"));
HttpRequest.newBuilder().uri(baseUri.resolve("/restate/awakeables/" + id + "/resolve"));

// Add content-type
if (serde.contentType() != null) {
Expand Down Expand Up @@ -132,11 +132,11 @@ public <T> CompletableFuture<Void> resolve(Serde<T> serde, @NonNull T payload) {
}

@Override
public CompletableFuture<Void> reject(String reason) {
public CompletableFuture<Void> rejectAsync(String reason) {
// Prepare request
var reqBuilder =
HttpRequest.newBuilder()
.uri(URI.create("/restate/awakeables/" + id + "/reject"))
.uri(baseUri.resolve("/restate/awakeables/" + id + "/reject"))
.header("content-type", "text-plain");

// Add headers
Expand Down
28 changes: 26 additions & 2 deletions sdk-common/src/main/java/dev/restate/sdk/client/IngressClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,44 @@ default <Req> String send(Target target, Serde<Req> reqSerde, Req req) throws In
* ingress
*/
interface AwakeableHandle {
/** Same as {@link #resolve(Serde, Object)} but async. */
<T> CompletableFuture<Void> resolveAsync(Serde<T> serde, @NonNull T payload);

/**
* Complete with success the Awakeable.
*
* @param serde used to serialize the Awakeable result payload.
* @param payload the result payload. MUST NOT be null.
*/
<T> CompletableFuture<Void> resolve(Serde<T> serde, @NonNull T payload);
default <T> void resolve(Serde<T> serde, @NonNull T payload) {
try {
resolveAsync(serde, payload).join();
} catch (CompletionException e) {
if (e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
}
throw new RuntimeException(e.getCause());
}
}

/** Same as {@link #reject(String)} but async. */
CompletableFuture<Void> rejectAsync(String reason);

/**
* Complete with failure the Awakeable.
*
* @param reason the rejection reason. MUST NOT be null.
*/
CompletableFuture<Void> reject(String reason);
default void reject(String reason) {
try {
rejectAsync(reason).join();
} catch (CompletionException e) {
if (e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
}
throw new RuntimeException(e.getCause());
}
}
}

static IngressClient defaultClient(String baseUri) {
Expand Down
Loading