Skip to content

Commit 0bbde7e

Browse files
Add sendEvent on Workflows instance (#3872)
* WOR-603: Add sendEvent on Workflows instance * Generated schemas --------- Co-authored-by: André Cruz <[email protected]>
1 parent a8aee5c commit 0bbde7e

File tree

23 files changed

+246
-10
lines changed

23 files changed

+246
-10
lines changed

src/cloudflare/internal/workflows-api.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,20 @@ class InstanceImpl implements WorkflowInstance {
7777
});
7878
return result;
7979
}
80+
81+
public async sendEvent({
82+
type,
83+
payload,
84+
}: {
85+
type: string;
86+
payload: unknown;
87+
}): Promise<void> {
88+
await callFetcher(this.fetcher, '/send-event', {
89+
type,
90+
payload,
91+
id: this.id,
92+
});
93+
}
8094
}
8195

8296
class WorkflowImpl {

src/cloudflare/internal/workflows.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,15 @@ declare abstract class WorkflowInstance {
109109
* Returns the current status of the instance.
110110
*/
111111
public status(): Promise<InstanceStatus>;
112+
113+
/**
114+
* Send an event to this instance.
115+
*/
116+
public sendEvent({
117+
type,
118+
payload,
119+
}: {
120+
type: string;
121+
payload: unknown;
122+
}): Promise<void>;
112123
}

types/defines/workflows.d.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
declare module "cloudflare:workflows" {
1+
declare module 'cloudflare:workflows' {
22
/**
33
* NonRetryableError allows for a user to throw a fatal error
44
* that makes a Workflow instance fail immediately without triggering a retry
@@ -49,15 +49,15 @@ interface WorkflowInstanceCreateOptions<PARAMS = unknown> {
4949

5050
type InstanceStatus = {
5151
status:
52-
| "queued" // means that instance is waiting to be started (see concurrency limits)
53-
| "running"
54-
| "paused"
55-
| "errored"
56-
| "terminated" // user terminated the instance while it was running
57-
| "complete"
58-
| "waiting" // instance is hibernating and waiting for sleep or event to finish
59-
| "waitingForPause" // instance is finishing the current work to pause
60-
| "unknown";
52+
| 'queued' // means that instance is waiting to be started (see concurrency limits)
53+
| 'running'
54+
| 'paused'
55+
| 'errored'
56+
| 'terminated' // user terminated the instance while it was running
57+
| 'complete'
58+
| 'waiting' // instance is hibernating and waiting for sleep or event to finish
59+
| 'waitingForPause' // instance is finishing the current work to pause
60+
| 'unknown';
6161
error?: string;
6262
output?: object;
6363
};
@@ -94,4 +94,15 @@ declare abstract class WorkflowInstance {
9494
* Returns the current status of the instance.
9595
*/
9696
public status(): Promise<InstanceStatus>;
97+
98+
/**
99+
* Send an event to this instance.
100+
*/
101+
public sendEvent({
102+
type,
103+
payload,
104+
}: {
105+
type: string;
106+
payload: unknown;
107+
}): Promise<void>;
97108
}

types/generated-snapshot/2021-11-03/index.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6986,4 +6986,14 @@ declare abstract class WorkflowInstance {
69866986
* Returns the current status of the instance.
69876987
*/
69886988
public status(): Promise<InstanceStatus>;
6989+
/**
6990+
* Send an event to this instance.
6991+
*/
6992+
public sendEvent({
6993+
type,
6994+
payload,
6995+
}: {
6996+
type: string;
6997+
payload: unknown;
6998+
}): Promise<void>;
69896999
}

types/generated-snapshot/2021-11-03/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6841,4 +6841,14 @@ export declare abstract class WorkflowInstance {
68416841
* Returns the current status of the instance.
68426842
*/
68436843
public status(): Promise<InstanceStatus>;
6844+
/**
6845+
* Send an event to this instance.
6846+
*/
6847+
public sendEvent({
6848+
type,
6849+
payload,
6850+
}: {
6851+
type: string;
6852+
payload: unknown;
6853+
}): Promise<void>;
68446854
}

types/generated-snapshot/2022-01-31/index.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7012,4 +7012,14 @@ declare abstract class WorkflowInstance {
70127012
* Returns the current status of the instance.
70137013
*/
70147014
public status(): Promise<InstanceStatus>;
7015+
/**
7016+
* Send an event to this instance.
7017+
*/
7018+
public sendEvent({
7019+
type,
7020+
payload,
7021+
}: {
7022+
type: string;
7023+
payload: unknown;
7024+
}): Promise<void>;
70157025
}

types/generated-snapshot/2022-01-31/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6867,4 +6867,14 @@ export declare abstract class WorkflowInstance {
68676867
* Returns the current status of the instance.
68686868
*/
68696869
public status(): Promise<InstanceStatus>;
6870+
/**
6871+
* Send an event to this instance.
6872+
*/
6873+
public sendEvent({
6874+
type,
6875+
payload,
6876+
}: {
6877+
type: string;
6878+
payload: unknown;
6879+
}): Promise<void>;
68706880
}

types/generated-snapshot/2022-03-21/index.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7038,4 +7038,14 @@ declare abstract class WorkflowInstance {
70387038
* Returns the current status of the instance.
70397039
*/
70407040
public status(): Promise<InstanceStatus>;
7041+
/**
7042+
* Send an event to this instance.
7043+
*/
7044+
public sendEvent({
7045+
type,
7046+
payload,
7047+
}: {
7048+
type: string;
7049+
payload: unknown;
7050+
}): Promise<void>;
70417051
}

types/generated-snapshot/2022-03-21/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6893,4 +6893,14 @@ export declare abstract class WorkflowInstance {
68936893
* Returns the current status of the instance.
68946894
*/
68956895
public status(): Promise<InstanceStatus>;
6896+
/**
6897+
* Send an event to this instance.
6898+
*/
6899+
public sendEvent({
6900+
type,
6901+
payload,
6902+
}: {
6903+
type: string;
6904+
payload: unknown;
6905+
}): Promise<void>;
68966906
}

types/generated-snapshot/2022-08-04/index.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7039,4 +7039,14 @@ declare abstract class WorkflowInstance {
70397039
* Returns the current status of the instance.
70407040
*/
70417041
public status(): Promise<InstanceStatus>;
7042+
/**
7043+
* Send an event to this instance.
7044+
*/
7045+
public sendEvent({
7046+
type,
7047+
payload,
7048+
}: {
7049+
type: string;
7050+
payload: unknown;
7051+
}): Promise<void>;
70427052
}

0 commit comments

Comments
 (0)