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
3 changes: 2 additions & 1 deletion src/cloudflare/internal/workflows-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ class InstanceImpl implements WorkflowInstance {
});
}

async restart(): Promise<void> {
async restart(options?: WorkflowInstanceRestartOptions): Promise<void> {
await callFetcher(this.fetcher, '/restart', {
id: this.id,
step: options?.from,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MEDIUM] No test coverage for the new restart-from-step feature. The existing test file (src/cloudflare/internal/test/workflows/workflows-api-test.js) doesn't exercise restart() at all, and the mock (workflows-mock.js) has no /restart handler.

Please consider adding tests that:

  • call restart() with no arguments (existing behavior)
  • call restart({ from: { name: 'stepName' } }) and verify the mock receives { id, step: { name: 'stepName' } }
  • call restart({ from: { name: 'stepName', count: 2, type: 'do' } }) to cover the full shape

});
}

Expand Down
21 changes: 19 additions & 2 deletions src/cloudflare/internal/workflows.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,21 @@ interface WorkflowError {
message: string;
}

interface WorkflowInstanceRestartOptions {
/**
* Restart from a specific step. If omitted, the instance restarts from the beginning.
* The step must exist in the instance's execution history.
*/
from?: {
/** The step name as defined in your workflow code. */
name: string;
/** 1-indexed occurrence of this step name. Defaults to 1. Use when the same step name appears multiple times (e.g. in a loop). */
count?: number;
/** Step type filter. Use when different step types share the same name. */
type?: 'do' | 'sleep' | 'waitForEvent';
};
}

declare abstract class WorkflowInstance {
id: string;

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

/**
* Restart the instance.
* Restart the instance. Optionally restart from a specific step, preserving
* cached results for all steps before it.
* @param options Options for the restart, including an optional step to restart from.
*/
restart(): Promise<void>;
restart(options?: WorkflowInstanceRestartOptions): Promise<void>;

/**
* Returns the current status of the instance.
Expand Down
Loading