Skip to content

Commit

Permalink
Fix links and small fixes of examples
Browse files Browse the repository at this point in the history
  • Loading branch information
gvdongen committed Jan 9, 2025
1 parent 3512439 commit 07494f6
Show file tree
Hide file tree
Showing 19 changed files with 191 additions and 173 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,34 @@
import develop.workflows.Email;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import usecases.asynctasks.synctoasync.DataPreparationServiceClient.IngressClient;

public class MyClient {
// <start_here>
public void downloadData(String userId, Email email) {
// <mark_1>
Client rs = Client.connect("http://localhost:8080");
IngressClient client = DataPreparationServiceClient.fromClient(rs, userId);
IngressClient uploadClient = DataPreparationServiceClient.fromClient(rs, userId);
// </mark_1>
// <mark_2>
client.submit();
uploadClient.submit();
// </mark_2>

try {
// <mark_3>
CompletableFuture.anyOf(client.workflowHandle().attachAsync())
uploadClient.workflowHandle().attachAsync()
.orTimeout(30, TimeUnit.SECONDS)
.join();
// </mark_3>
// <mark_4>
} catch (Exception e) {
client.resultAsEmail(email);
return;
if (e.getCause() instanceof TimeoutException) {
uploadClient.resultAsEmail(email);
return;
}
throw e;
}
// </mark_4>
// ... process directly ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import dev.restate.sdk.client.CallRequestOptions;
import dev.restate.sdk.client.Client;

class Config {
public static String RESTATE_URL = "http://localhost:8080";
}

public class Idempotency {

public static String RESTATE_URL = "http://localhost:8080";

// <start_here>
Client rs = Client.connect(Config.RESTATE_URL);
Client rs = Client.connect(RESTATE_URL);

public void reserveProduct(String productId, String reservationId) {
// <mark_1>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class User(BaseModel):


# <start_here>
def download_data(user: User):
def upload_data(user: User):
headers = {"Content-Type": "application/json"}
try:
# <mark_1>
Expand All @@ -32,7 +32,3 @@ def download_data(user: User):
# ... process result directly ...
# </mark_4>
# <end_here>


async def read_line(prompt: str) -> str:
return await asyncio.get_event_loop().run_in_executor(None, input, prompt)
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const asyncTaskService = restate.service({

export type AsyncTaskService = typeof asyncTaskService;

const endpoint = restate.endpoint().bind(asyncTaskService).listen(9080);
restate.endpoint().bind(asyncTaskService).listen(9080);
// <end_here>

// ----------------------- Stubs to please the compiler -----------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,29 @@ const RESTATE_URL = process.env.RESTATE_URL ?? "http://localhost:8080";

// <start_here>
async function submitAndAwaitTask(task: TaskOpts) {
const rs = restate.connect({ url: RESTATE_URL });
const restateClient = restate.connect({ url: RESTATE_URL });

// <mark_1>
const taskHandle = await rs
const taskHandle = await restateClient
.serviceSendClient<AsyncTaskService>({ name: "taskWorker" })
.runTask(
task,
// <mark_2>
restate.rpc.sendOpts({ idempotencyKey: "dQw4w9WgXcQ" })
SendOpts.from({ idempotencyKey: "dQw4w9WgXcQ" })
// </mark_2>
);
// </mark_1>

// await the handler's result
// <mark_3>
const result = await rs.result(taskHandle);
const result = await restateClient.result(taskHandle);
// </mark_3>
}

// <mark_4>
async function attachToTask(taskHandle: string) {
const rs = restate.connect({ url: RESTATE_URL });
const result2 = await rs.result<string>(JSON.parse(taskHandle));
const result = await rs.result<string>(JSON.parse(taskHandle));
}
// </mark_4>
// <end_here>
3 changes: 1 addition & 2 deletions code_snippets/ts/src/use_cases/microservices/idempotency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ process.env.RESTATE_URL = "localhost:8080";

// <start_here>
const rs = restate.connect({ url: process.env.RESTATE_URL });
const productService: ProductService = { name: "product" };

app.get("/reserve/:product/:reservationId", async (req, res) => {
const { product, reservationId } = req.params;

// !mark(1:5)
const products = rs.serviceClient(productService);
const products = rs.serviceClient<ProductService>({ name: "product" });
const reservation = await products.reserve(
product,
Opts.from({ idempotencyKey: reservationId })
Expand Down
2 changes: 1 addition & 1 deletion docs/deploy/faas/deno-deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description: "TypeScript services on Deno Deploy."
You can run your Restate services as serverless functions on [Deno Deploy](https://deno.com/deploy).

You can easily get started using the
[Deno+Restate template](https://github.com/restatedev/examples/tree/main/templates/deno):
[Deno+Restate template](https://github.com/restatedev/examples/tree/main/typescript/templates/deno):
```shell CLI
restate example typescript-deno-hello-world &&
cd typescript-deno-hello-world
Expand Down
6 changes: 2 additions & 4 deletions docs/deploy/faas/lambda/cdk.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,7 @@ deployer.deployService("RestateService", serviceHandler.currentVersion, restateE

You can use the following examples as references for your own CDK projects:

- [hello-world-lambda-cdk (Kotlin)](https://github.com/restatedev/examples/tree/main/templates/kotlin-gradle-lambda-cdk) -
provides a simple example of a Lambda-deployed Kotlin handler with a CDK stack modeled in TypeScript
- [hello-world-lambda-cdk (TypeScript)](https://github.com/restatedev/examples/tree/main/templates/typescript-lambda-cdk) -
provides a simple example of a Lambda-deployed TypeScript handler with a CDK stack modeled in TypeScript
- [hello-world-lambda-cdk (Kotlin)](https://github.com/restatedev/examples/tree/main/README.md#aws-lambda) -
provides a simple example of a Lambda-deployed handler with a CDK stack.
- [Restate Holiday](https://github.com/restatedev/restate-holiday) - a more complex example of a fictional reservation
service demonstrating the Saga orchestration pattern across multiple Restate services implemented in TypeScript
2 changes: 1 addition & 1 deletion docs/deploy/faas/lambda/lambda-java.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ tasks.withType<ShadowJar> {
}
```

For a complete Gradle build script example please see the example [hello-world-lambda-cdk](https://github.com/restatedev/examples/blob/main/templates/kotlin-gradle-lambda-cdk/lambda/build.gradle.kts).
For a complete Gradle build script example please see the example [hello-world-lambda-cdk](https://github.com/restatedev/examples/blob/main/kotlin/integrations/kotlin-gradle-lambda-cdk/lambda/build.gradle.kts).

Now build the Fat-JAR. For example, using Gradle:

Expand Down
2 changes: 1 addition & 1 deletion docs/deploy/faas/workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description: "TypeScript services on Cloudflare Workers."
You can run your Restate services as serverless functions on [Cloudflare Workers](https://workers.cloudflare.com/).

You can easily get started using the
[Workers+Restate template](https://github.com/restatedev/examples/tree/main/templates/cloudflare-worker):
[Workers+Restate template](https://github.com/restatedev/examples/tree/main/typescript/templates/cloudflare-worker):
```shell CLI
restate example typescript-cloudflare-worker-hello-world &&
cd typescript-cloudflare-worker-hello-world
Expand Down
26 changes: 13 additions & 13 deletions docs/get_started/quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -544,22 +544,22 @@ We will run a simple Restate Greeter service that listens on port `9080` and res
<Tabs groupId={"ts-runtime"} className={"display-none"}>
<TabItem value={"Node.js"}>
```ts
CODE_LOAD::https://raw.githubusercontent.com/restatedev/examples/refs/heads/main/templates/typescript/src/app.ts
CODE_LOAD::https://raw.githubusercontent.com/restatedev/examples/refs/heads/main/typescript/templates/node/src/app.ts
```
</TabItem>
<TabItem value={"Bun"}>
```ts
CODE_LOAD::https://raw.githubusercontent.com/restatedev/examples/refs/heads/main/templates/bun/src/index.ts
CODE_LOAD::https://raw.githubusercontent.com/restatedev/examples/refs/heads/main/typescript/templates/bun/src/index.ts
```
</TabItem>
<TabItem value={"Deno"}>
```ts
CODE_LOAD::https://raw.githubusercontent.com/restatedev/examples/refs/heads/main/templates/deno/main.ts
CODE_LOAD::https://raw.githubusercontent.com/restatedev/examples/refs/heads/main/typescript/templates/deno/main.ts
```
</TabItem>
<TabItem value={"CloudflareWorkers"} >
```ts
CODE_LOAD::https://raw.githubusercontent.com/restatedev/examples/refs/heads/main/templates/cloudflare-worker/src/index.ts
CODE_LOAD::https://raw.githubusercontent.com/restatedev/examples/refs/heads/main/typescript/templates/cloudflare-worker/src/index.ts
```
</TabItem>
</Tabs>
Expand Down Expand Up @@ -957,23 +957,23 @@ We will run a simple Restate Greeter service that listens on port `9080` and res
// !collapse(1:13) collapsed
// !mark[//\/\ Click to expand imports/] grey
// Click to expand imports
CODE_LOAD::https://raw.githubusercontent.com/restatedev/examples/refs/heads/main/templates/java-maven-spring-boot/src/main/java/com/example/restatestarter/Greeter.java
CODE_LOAD::https://raw.githubusercontent.com/restatedev/examples/refs/heads/main/java/templates/java-maven-spring-boot/src/main/java/com/example/restatestarter/Greeter.java
```
</TabItem>
<TabItem value={"quarkus"}>
```java
// !collapse(1:15) collapsed
// !mark[//\/\ Click to expand imports/] grey
// Click to expand imports
CODE_LOAD::https://raw.githubusercontent.com/restatedev/examples/refs/heads/main/templates/java-maven-quarkus/src/main/java/org/acme/Greeter.java
CODE_LOAD::https://raw.githubusercontent.com/restatedev/examples/refs/heads/main/java/templates/java-maven-quarkus/src/main/java/org/acme/Greeter.java
```
</TabItem>
<TabItem value={"vanilla"}>
```java
// !collapse(1:13) collapsed
// !mark[//\/\ Click to expand imports/] grey
// Click to expand imports
CODE_LOAD::https://raw.githubusercontent.com/restatedev/examples/refs/heads/main/templates/java-maven/src/main/java/my/example/Greeter.java
CODE_LOAD::https://raw.githubusercontent.com/restatedev/examples/refs/heads/main/java/templates/java-maven/src/main/java/my/example/Greeter.java
```
</TabItem>
</Tabs>
Expand All @@ -985,7 +985,7 @@ We will run a simple Restate Greeter service that listens on port `9080` and res
// !collapse(1:13) collapsed
// !mark[//\/\ Click to expand imports/] grey
// Click to expand imports
CODE_LOAD::https://raw.githubusercontent.com/restatedev/examples/refs/heads/main/templates/java-gradle/src/main/java/my/example/Greeter.java
CODE_LOAD::https://raw.githubusercontent.com/restatedev/examples/refs/heads/main/java/templates/java-gradle/src/main/java/my/example/Greeter.java
```
</TabItem>
</Tabs>
Expand Down Expand Up @@ -1213,7 +1213,7 @@ We will run a simple Restate Greeter service that listens on port `9080` and res
// !collapse(1:10) collapsed
// !mark[//\/\ Click to expand imports/] grey
// Click to expand imports
CODE_LOAD::https://raw.githubusercontent.com/restatedev/examples/refs/heads/main/templates/kotlin-gradle/src/main/kotlin/my/example/Greeter.kt
CODE_LOAD::https://raw.githubusercontent.com/restatedev/examples/refs/heads/main/kotlin/templates/kotlin-gradle/src/main/kotlin/my/example/Greeter.kt
```

It sometimes failed to send the notification and the reminder.
Expand Down Expand Up @@ -1445,7 +1445,7 @@ We will run a simple Restate Greeter service that listens on port `9080` and res
// !collapse(1:8) collapsed
// !mark[//\/\ Click to expand imports/] grey
// Click to expand imports
CODE_LOAD::https://raw.githubusercontent.com/restatedev/examples/refs/heads/main/templates/go/greeter.go
CODE_LOAD::https://raw.githubusercontent.com/restatedev/examples/refs/heads/main/go/templates/go/greeter.go
```

It sometimes failed to send the notification and the reminder.
Expand Down Expand Up @@ -1695,7 +1695,7 @@ We will run a simple Restate Greeter service that listens on port `9080` and res
# !collapse(1:8) collapsed
# !mark[/# Click to expand imports/] grey
# Click to expand imports
CODE_LOAD::https://raw.githubusercontent.com/restatedev/examples/refs/heads/main/templates/python/example.py
CODE_LOAD::https://raw.githubusercontent.com/restatedev/examples/refs/heads/main/python/templates/python/example.py
```

It sometimes failed to send the notification and the reminder.
Expand Down Expand Up @@ -2025,15 +2025,15 @@ We will run a simple Restate Greeter service that listens on port `9080` and res
// !collapse(1:12) collapsed
// !mark[//\/\ Click to expand imports/] grey
// Click to expand imports
CODE_LOAD::https://raw.githubusercontent.com/restatedev/examples/refs/heads/main/templates/rust/src/main.rs
CODE_LOAD::https://raw.githubusercontent.com/restatedev/examples/refs/heads/main/rust/templates/rust/src/main.rs
```
</TabItem>
<TabItem value={"Shuttle"}>
```rust
// !collapse(1:10) collapsed
// !mark[//\/\ Click to expand imports/] grey
// Click to expand imports
CODE_LOAD::https://raw.githubusercontent.com/restatedev/examples/refs/heads/main/templates/rust-shuttle/src/main.rs
CODE_LOAD::https://raw.githubusercontent.com/restatedev/examples/refs/heads/main/rust/templates/rust-shuttle/src/main.rs
```
</TabItem>
</Tabs>
Expand Down
Loading

0 comments on commit 07494f6

Please sign in to comment.