-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5756ec6
commit b0a027b
Showing
12 changed files
with
412 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
contracts/src/main/java/my/restate/e2e/services/WorkflowAPIBlockAndWait.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) 2024 - Restate Software, Inc., Restate GmbH | ||
// | ||
// This file is part of the Restate e2e tests, | ||
// which are released under the MIT license. | ||
// | ||
// You can find a copy of the license in file LICENSE in the root | ||
// directory of this repository or package, or at | ||
// https://github.com/restatedev/e2e/blob/main/LICENSE | ||
|
||
package my.restate.e2e.services; | ||
|
||
import dev.restate.sdk.annotation.Service; | ||
import dev.restate.sdk.annotation.ServiceType; | ||
import dev.restate.sdk.annotation.Shared; | ||
import dev.restate.sdk.annotation.Workflow; | ||
import dev.restate.sdk.common.StateKey; | ||
import dev.restate.sdk.workflow.WorkflowContext; | ||
import dev.restate.sdk.workflow.WorkflowSharedContext; | ||
|
||
@Service(ServiceType.WORKFLOW) | ||
public interface WorkflowAPIBlockAndWait { | ||
|
||
@Workflow | ||
String blockAndWait(WorkflowContext context, String input); | ||
|
||
@Shared | ||
void unblock(WorkflowSharedContext context, String output); | ||
|
||
StateKey<String> MY_STATE = StateKey.string("my-state"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...ices/java-services/src/main/java/my/restate/e2e/services/WorkflowAPIBlockAndWaitImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) 2024 - Restate Software, Inc., Restate GmbH | ||
// | ||
// This file is part of the Restate e2e tests, | ||
// which are released under the MIT license. | ||
// | ||
// You can find a copy of the license in file LICENSE in the root | ||
// directory of this repository or package, or at | ||
// https://github.com/restatedev/e2e/blob/main/LICENSE | ||
|
||
package my.restate.e2e.services; | ||
|
||
import dev.restate.sdk.common.TerminalException; | ||
import dev.restate.sdk.workflow.DurablePromiseKey; | ||
import dev.restate.sdk.workflow.WorkflowContext; | ||
import dev.restate.sdk.workflow.WorkflowSharedContext; | ||
|
||
public class WorkflowAPIBlockAndWaitImpl implements WorkflowAPIBlockAndWait { | ||
|
||
private static final DurablePromiseKey<String> MY_DURABLE_PROMISE = | ||
DurablePromiseKey.string("durable-promise"); | ||
|
||
@Override | ||
public String blockAndWait(WorkflowContext context, String input) { | ||
context.set(MY_STATE, input); | ||
|
||
// Wait on unblock | ||
String output = context.durablePromise(MY_DURABLE_PROMISE).awaitable().await(); | ||
|
||
if (!context.durablePromise(MY_DURABLE_PROMISE).isCompleted()) { | ||
throw new TerminalException("Durable promise should be completed"); | ||
} | ||
if (context.durablePromise(MY_DURABLE_PROMISE).peek().isEmpty()) { | ||
throw new TerminalException("Durable promise should be completed"); | ||
} | ||
|
||
return output; | ||
} | ||
|
||
@Override | ||
public void unblock(WorkflowSharedContext context, String output) { | ||
context.durablePromiseHandle(MY_DURABLE_PROMISE).resolve(output); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) 2024 - Restate Software, Inc., Restate GmbH | ||
// | ||
// This file is part of the Restate e2e tests, | ||
// which are released under the MIT license. | ||
// | ||
// You can find a copy of the license in file LICENSE in the root | ||
// directory of this repository or package, or at | ||
// https://github.com/restatedev/e2e/blob/main/LICENSE | ||
|
||
import * as restate from "@restatedev/restate-sdk"; | ||
|
||
const MY_STATE = "my-state"; | ||
const MY_DURABLE_PROMISE = "durable-promise"; | ||
|
||
export const WorkflowAPIBlockAndWaitFQN = "WorkflowAPIBlockAndWait"; | ||
|
||
export const WorkflowAPIBlockAndWait = restate.workflow.workflow( | ||
WorkflowAPIBlockAndWaitFQN, | ||
{ | ||
run: async (ctx: restate.workflow.WfContext, params: { input: string }) => { | ||
ctx.console.log("input: " + JSON.stringify(params)); | ||
ctx.set(MY_STATE, params.input); | ||
|
||
// Wait on unblock | ||
const p = ctx.promise<string>(MY_DURABLE_PROMISE); | ||
const output = await p.promise(); | ||
|
||
// Check peek works | ||
ctx.console.assert((await p.peek()) == output); | ||
|
||
return output; | ||
}, | ||
|
||
unblock: async ( | ||
ctx: restate.workflow.SharedWfContext, | ||
params: { output: string } | ||
) => { | ||
ctx.promise<string>(MY_DURABLE_PROMISE).resolve(params.output); | ||
}, | ||
|
||
getState: async ( | ||
ctx: restate.workflow.SharedWfContext | ||
): Promise<string> => { | ||
return (await ctx.get(MY_STATE)) ?? "(not yet set)"; | ||
}, | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.