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
5 changes: 5 additions & 0 deletions .changeset/ninety-dancers-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@workflow/core": patch
---

Make `getWorld` asynchronous so it can use dynamic imports
10 changes: 5 additions & 5 deletions docs/content/docs/api-reference/workflow-api/get-world.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ title: getWorld
description: Access the World instance for low-level storage, queuing, and streaming operations.
---

Retrieves the World instance for direct access to workflow storage, queuing, and streaming backends. This function returns a `World` which provides low-level access to manage workflow runs, steps, events, and hooks.
Retrieves the World instance for direct access to workflow storage, queuing, and streaming backends. This async function returns a `Promise<World>` which provides low-level access to manage workflow runs, steps, events, and hooks.

Use this function when you need direct access to the underlying workflow infrastructure, such as listing all runs, querying events, or implementing custom workflow management logic.

```typescript lineNumbers
import { getWorld } from "workflow/runtime";

const world = getWorld();
const world = await getWorld();
```

## API Signature
Expand All @@ -21,7 +21,7 @@ This function does not accept any parameters.

### Returns

Returns a `World` object:
Returns a `Promise<World>` object:

<TSDoc
definition={`
Expand All @@ -44,7 +44,7 @@ export async function GET(req: Request) {
const cursor = url.searchParams.get("cursor") ?? undefined;

try {
const world = getWorld(); // [!code highlight]
const world = await getWorld(); // [!code highlight]
const runs = await world.runs.list({
pagination: { cursor },
});
Expand Down Expand Up @@ -74,7 +74,7 @@ export async function POST(req: Request) {
}

try {
const world = getWorld(); // [!code highlight]
const world = await getWorld(); // [!code highlight]
const run = await world.runs.cancel(runId); // [!code highlight]

return Response.json({ status: run.status });
Expand Down
13 changes: 9 additions & 4 deletions docs/content/docs/deploying/world/postgres-world.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ Create an `instrumentation.ts` file in your project root:
export async function register() {
if (process.env.NEXT_RUNTIME !== "edge") {
const { getWorld } = await import("workflow/runtime");
await getWorld().start?.();
const world = await getWorld();
await world.start?.();
}
}
```
Expand All @@ -66,7 +67,8 @@ import type { ServerInit } from "@sveltejs/kit";

export const init: ServerInit = async () => {
const { getWorld } = await import("workflow/runtime");
await getWorld().start?.();
const world = await getWorld();
await world.start?.();
};
```

Expand All @@ -85,7 +87,8 @@ import { defineNitroPlugin } from "nitro/~internal/runtime/plugin";

export default defineNitroPlugin(async () => {
const { getWorld } = await import("workflow/runtime");
await getWorld().start?.();
const world = await getWorld();
await world.start?.();
});
```

Expand Down Expand Up @@ -155,7 +158,8 @@ Number of concurrent workers polling for jobs. Default: `10`

### Programmatic configuration

{/* @skip-typecheck: incomplete code sample */}
{/*@skip-typecheck: incomplete code sample*/}

```typescript title="workflow.config.ts" lineNumbers
import { createWorld } from "@workflow/world-postgres";

Expand Down Expand Up @@ -186,6 +190,7 @@ Deploy your application to any cloud that supports long-running servers:
- Platform-as-a-Service providers (Railway, Render, Fly.io, etc.)

Ensure your deployment has:

1. Network access to your PostgreSQL database
2. Environment variables configured correctly
3. The `start()` function called on server initialization
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/lib/inspect/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const getEnvVars = (): Record<string, string> => {
WORKFLOW_VERCEL_PROJECT: env.WORKFLOW_VERCEL_PROJECT || '',
WORKFLOW_VERCEL_TEAM: env.WORKFLOW_VERCEL_TEAM || '',
WORKFLOW_LOCAL_UI: env.WORKFLOW_LOCAL_UI || '',
WORKFLOW_LOCAL_BASE_URL: env.WORKFLOW_LOCAL_BASE_URL || '',
PORT: env.PORT || '',
WORKFLOW_LOCAL_DATA_DIR: env.WORKFLOW_LOCAL_DATA_DIR || '',
WORKFLOW_MANIFEST_PATH: env.WORKFLOW_MANIFEST_PATH || '',
Expand Down
Loading
Loading