Skip to content
Draft
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
15 changes: 15 additions & 0 deletions src/content/docs/workflows/build/trigger-workflows.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,21 @@ let instance = await env.MY_WORKFLOW.get("abc-123");
await instance.terminate(); // Returns Promise<void>
```

To run registered rollback handlers before terminating, pass `rollback: true`:

```ts
let instance = await env.MY_WORKFLOW.get("abc-123");
await instance.terminate({ rollback: true }); // Returns Promise<void>
```

You can also run rollback handlers from Wrangler:

```sh
npx wrangler workflows instances terminate <WORKFLOW_NAME> <INSTANCE_ID> --rollback
# For a local Workflows instance during wrangler dev:
npx wrangler workflows instances terminate <WORKFLOW_NAME> <INSTANCE_ID> --local --rollback
```

Once stopped/terminated, the Workflow instance _cannot_ be resumed.

### Restart a Workflow
Expand Down
28 changes: 26 additions & 2 deletions src/content/docs/workflows/build/workers-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ declare abstract class WorkflowInstance {
/**
* Terminate the instance. If it is errored, terminated or complete, an error will be thrown.
*/
public terminate(): Promise<void>;
public terminate(options?: WorkflowInstanceTerminateOptions): Promise<void>;
/**
* Restart the instance.
*/
Expand Down Expand Up @@ -523,7 +523,31 @@ Restart a Workflow instance.

Terminate a Workflow instance.

- <code>terminate(): Promise&lt;void&gt;</code>
- <code>terminate(options?: WorkflowInstanceTerminateOptions): Promise&lt;void&gt;</code>
- `options` - optional properties that control how the instance is terminated.

```ts
let instance = await env.MY_WORKFLOW.get("abc-123");

// Terminate without running rollback handlers.
await instance.terminate();

// Run registered rollback handlers before terminating.
await instance.terminate({ rollback: true });
```

If `rollback` is `true`, Workflows runs the rollback handlers registered by completed or eligible steps before the instance reaches the `terminated` state. Steps without rollback handlers are skipped.

#### WorkflowInstanceTerminateOptions

```ts
interface WorkflowInstanceTerminateOptions {
/**
* If true, run registered rollback handlers before terminating the instance.
*/
rollback?: boolean;
}
```

### sendEvent

Expand Down
Loading