Skip to content
Open
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
4 changes: 2 additions & 2 deletions docs/content/docs/workflows.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ Deploy the app, then connect to its actors from your own system:

<CodeSnippet file="examples/apps-workflows/src/client.ts" region="client" title="Client" />

See [Workflows in Rivet Actors](/workflows/docs/) for
steps, loops, queues, and error handling.
The app defines its actor with `@rivet-dev/workflows`. See the
[Workflows docs](/workflows/docs/) for steps, loops, queues, and error handling.
9 changes: 6 additions & 3 deletions examples/apps-workflows/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Dynamic Apps: Workflows

The deployed app defines a keyed job actor whose durable workflow starts when
the actor is created, sleeps, and resumes before marking the job complete.
The deployed app defines an `order` actor with
[`@rivet-dev/workflows`](https://rivet.dev/workflows/docs/). Its durable
workflow starts when the actor is created, charges and ships the order, sleeps
while it is in transit, and resumes to mark it delivered. The client deploys the
app as `order-workflow` and polls the order's status until it is delivered.

Run the example with Node.js 22 or newer:

Expand All @@ -12,4 +15,4 @@ pnpm --dir examples/apps-workflows client
```

The app's ordinary HTTP handler is available at
`http://localhost:3000/apps/durable-workflow/`.
`http://localhost:3000/apps/order-workflow/`.
1 change: 1 addition & 0 deletions examples/apps-workflows/fixtures/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"type": "module",
"main": "src/index.ts",
"dependencies": {
"@rivet-dev/workflows": "1.0.0",
"hono": "4.13.5",
"rivetkit": "2.3.11"
}
Expand Down
9 changes: 4 additions & 5 deletions examples/apps-workflows/fixtures/app/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { setup, workflow } from "@rivet-dev/workflows";
import { Hono } from "hono";
import { actor, setup } from "rivetkit";
import { workflow } from "rivetkit/workflow";

type Status = "placed" | "paid" | "shipped" | "delivered";

// The workflow runs when the actor is created. Each step is durable, so the
// actor can sleep, scale to zero, and resume exactly where it left off.
const order = actor({
const order = workflow({
state: { status: "placed" as Status },
actions: {
status: (c) => c.state.status,
},
run: workflow(async (wf) => {
run: async (wf) => {
await wf.step("charge", async (c) => {
c.state.status = "paid";
});
Expand All @@ -22,7 +21,7 @@ const order = actor({
await wf.step("deliver", async (c) => {
c.state.status = "delivered";
});
}),
},
});

export const registry = setup({ use: { order } });
Expand Down
1 change: 1 addition & 0 deletions examples/apps-workflows/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"dependencies": {
"@hono/node-server": "^2.1.1",
"@rivet-dev/dynamic-apps": "workspace:*",
"@rivet-dev/workflows": "1.0.0",
"hono": "^4.13.5",
"rivetkit": "2.3.11"
},
Expand Down
18 changes: 18 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading