Skip to content

Commit 49c3f33

Browse files
vaishnav-mkavenceslau
authored andcommitted
add restart-from-step support to WorkflowInstance.restart() — uses { from: { name, count?, type? } }
1 parent 58de6ba commit 49c3f33

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

src/cloudflare/internal/workflows-api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ class InstanceImpl implements WorkflowInstance {
6767
});
6868
}
6969

70-
async restart(): Promise<void> {
70+
async restart(options?: WorkflowInstanceRestartOptions): Promise<void> {
7171
await callFetcher(this.fetcher, '/restart', {
7272
id: this.id,
73+
step: options?.from,
7374
});
7475
}
7576

src/cloudflare/internal/workflows.d.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,21 @@ interface WorkflowError {
108108
message: string;
109109
}
110110

111+
interface WorkflowInstanceRestartOptions {
112+
/**
113+
* Restart from a specific step. If omitted, the instance restarts from the beginning.
114+
* The step must exist in the instance's execution history.
115+
*/
116+
from?: {
117+
/** The step name as defined in your workflow code. */
118+
name: string;
119+
/** 1-indexed occurrence of this step name. Defaults to 1. Use when the same step name appears multiple times (e.g. in a loop). */
120+
count?: number;
121+
/** Step type filter. Use when different step types share the same name. */
122+
type?: 'do' | 'sleep' | 'waitForEvent';
123+
};
124+
}
125+
111126
declare abstract class WorkflowInstance {
112127
id: string;
113128

@@ -127,9 +142,11 @@ declare abstract class WorkflowInstance {
127142
terminate(): Promise<void>;
128143

129144
/**
130-
* Restart the instance.
145+
* Restart the instance. Optionally restart from a specific step, preserving
146+
* cached results for all steps before it.
147+
* @param options Options for the restart, including an optional step to restart from.
131148
*/
132-
restart(): Promise<void>;
149+
restart(options?: WorkflowInstanceRestartOptions): Promise<void>;
133150

134151
/**
135152
* Returns the current status of the instance.

0 commit comments

Comments
 (0)