Skip to content

Commit 3b60131

Browse files
Adds support for waitForEvent step type (#8981)
1 parent c8a5a60 commit 3b60131

File tree

5 files changed

+64
-9
lines changed

5 files changed

+64
-9
lines changed

.changeset/swift-hairs-run.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
Adds support for waitForEvent step type

packages/wrangler/src/__tests__/workflows.test.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,14 @@ describe("wrangler workflows", () => {
322322
},
323323
versionId: "14707576-2549-4848-82ed-f68f8a1b47c7",
324324
steps: [
325+
{
326+
type: "waitForEvent",
327+
end: "2021-01-01T00:00:00Z",
328+
name: "event",
329+
finished: true,
330+
output: {},
331+
start: "2021-01-01T00:00:00Z",
332+
},
325333
{
326334
attempts: [
327335
{
@@ -374,11 +382,24 @@ describe("wrangler workflows", () => {
374382

375383
await runWrangler(`workflows instances describe some-workflow bar`);
376384
expect(std.out).toMatchInlineSnapshot(`
377-
"┌───────────────────────┬───────────────────────┬───────────┬────────────┬────────────────┐
378-
│ Start │ End │ Duration │ State │ Error │
379-
├───────────────────────┼───────────────────────┼───────────┼────────────┼────────────────┤
380-
│ 1/1/2021, 12:00:00 AM │ 1/1/2021, 12:00:00 AM │ 0 seconds │ ✅ Success │ string: string │
381-
└───────────────────────┴───────────────────────┴───────────┴────────────┴────────────────┘"
385+
" Name: event
386+
Type: 👀 Waiting for event
387+
Start: 1/1/2021, 12:00:00 AM
388+
End: 1/1/2021, 12:00:00 AM
389+
Duration: 0 seconds
390+
Output: {}
391+
Name: string
392+
Type: 🎯 Step
393+
Start: 1/1/2021, 12:00:00 AM
394+
End: 1/1/2021, 12:00:00 AM
395+
Duration: 0 seconds
396+
Success: ✅ Yes
397+
Output: {}
398+
┌───────────────────────┬───────────────────────┬───────────┬────────────┬────────────────┐
399+
│ Start │ End │ Duration │ State │ Error │
400+
├───────────────────────┼───────────────────────┼───────────┼────────────┼────────────────┤
401+
│ 1/1/2021, 12:00:00 AM │ 1/1/2021, 12:00:00 AM │ 0 seconds │ ✅ Success │ string: string │
402+
└───────────────────────┴───────────────────────┴───────────┴────────────┴────────────────┘"
382403
`);
383404
});
384405
});

packages/wrangler/src/workflows/commands/instances/describe.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import type {
2222
InstanceStatusAndLogs,
2323
InstanceStepLog,
2424
InstanceTerminateLog,
25+
InstanceWaitForEventLog,
2526
} from "../../types";
2627

2728
export const workflowsInstancesDescribeCommand = createCommand({
@@ -140,12 +141,20 @@ export const workflowsInstancesDescribeCommand = createCommand({
140141

141142
function logStep(
142143
args: typeof workflowsInstancesDescribeCommand.args,
143-
step: InstanceStepLog | InstanceSleepLog | InstanceTerminateLog
144+
step:
145+
| InstanceStepLog
146+
| InstanceSleepLog
147+
| InstanceTerminateLog
148+
| InstanceWaitForEventLog
144149
) {
145150
logRaw("");
146151
const formattedStep: Record<string, string> = {};
147152

148-
if (step.type == "sleep" || step.type == "step") {
153+
if (
154+
step.type == "sleep" ||
155+
step.type == "step" ||
156+
step.type == "waitForEvent"
157+
) {
149158
formattedStep.Name = step.name;
150159
formattedStep.Type = emojifyStepType(step.type);
151160

@@ -197,6 +206,9 @@ function logStep(
197206
`${retryDate.toLocaleString()} (in ${formatDistanceToNowStrict(retryDate)} from now)`;
198207
}
199208
}
209+
}
210+
211+
if (step.type == "step" || step.type == "waitForEvent") {
200212
if (step.output !== undefined && args.stepOutput) {
201213
let output: string;
202214
try {
@@ -212,7 +224,7 @@ function logStep(
212224
}
213225
}
214226

215-
logRaw(formatLabelledValues(formattedStep, { indentationCount: 2 }));
227+
logger.log(formatLabelledValues(formattedStep, { indentationCount: 2 }));
216228

217229
if (step.type == "step") {
218230
const prettyAttempts = step.attempts.map((val) => {

packages/wrangler/src/workflows/types.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ export type InstanceTerminateLog = {
9191
};
9292
};
9393

94+
export type InstanceWaitForEventLog = {
95+
name: string;
96+
start: string;
97+
end: string;
98+
finished: boolean;
99+
error: { name: string; message: string } | null;
100+
output: unknown;
101+
type: "waitForEvent";
102+
};
103+
94104
export type InstanceStatusAndLogs = {
95105
status: InstanceStatus;
96106
params: Record<string, unknown>;
@@ -101,7 +111,12 @@ export type InstanceStatusAndLogs = {
101111
queued: string;
102112
start: string | null;
103113
end: string | null;
104-
steps: (InstanceStepLog | InstanceSleepLog | InstanceTerminateLog)[];
114+
steps: (
115+
| InstanceStepLog
116+
| InstanceSleepLog
117+
| InstanceTerminateLog
118+
| InstanceWaitForEventLog
119+
)[];
105120
success: boolean | null;
106121
error: { name: string; message: string } | null;
107122
};

packages/wrangler/src/workflows/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ export const emojifyStepType = (type: string) => {
4747
return "💤 Sleeping";
4848
case "termination":
4949
return "🚫 Termination";
50+
case "waitForEvent":
51+
return "👀 Waiting for event";
5052
default:
5153
return "❓ Unknown";
5254
}

0 commit comments

Comments
 (0)