Skip to content

Commit 21f62e7

Browse files
committed
Added tests and refactored response to use camelCase
1 parent c3564ca commit 21f62e7

4 files changed

Lines changed: 64 additions & 9 deletions

File tree

apps/webapp/app/services/events/cancelRunsForEvent.server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ export class CancelRunsForEventService {
6262
}
6363

6464
return {
65-
cancelled_run_ids: cancelledRunIds,
66-
failed_to_cancel_run_ids: failedToCancelRunIds,
65+
cancelledRunIds: cancelledRunIds,
66+
failedToCancelRunIds: failedToCancelRunIds,
6767
};
6868
});
6969
}

docs/sdk/triggerclient/instancemethods/cancel-runs-for-event.mdx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ description: "The `cancelRunsForEvent()` instance method will cancel all the job
1616

1717
<ResponseField type="object">
1818
<Expandable title="properties" defaultOpen>
19-
<ResponseField name="cancelled_run_ids" type="array" required>
19+
<ResponseField name="cancelledRunIds" type="array" required>
2020
List of Job Run IDs that are cancelled.
2121
</ResponseField>
22-
<ResponseField name="failed_to_cancel_run_ids" type="array" required>
22+
<ResponseField name="failedToCancelRunIds" type="array" required>
2323
List of Job Run IDs that have failed to be cancelled.
2424
</ResponseField>
2525
</Expandable>
@@ -32,10 +32,11 @@ const event = client.sendEvent({
3232
name: "test.job",
3333
});
3434

35-
const res = client.cancelRunsForEvent(event.id);
35+
// Some time later...
36+
const res = await client.cancelRunsForEvent(event.id);
3637

37-
console.log(res.cancelled_run_ids);
38-
console.log(res.failed_to_cancel_run_ids);
38+
console.log(res.cancelledRunIds);
39+
console.log(res.failedToCancelRunIds);
3940
```
4041

4142
</RequestExample>

packages/core/src/schemas/events.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export const GetEventSchema = z.object({
2828
export type GetEvent = z.infer<typeof GetEventSchema>;
2929

3030
export const CancelRunsForEventSchema = z.object({
31-
cancelled_run_ids: z.array(z.string()),
32-
failed_to_cancel_run_ids: z.array(z.string()),
31+
cancelledRunIds: z.array(z.string()),
32+
failedToCancelRunIds: z.array(z.string()),
3333
});
3434

3535
export type CancelRunsForEvent = z.infer<typeof CancelRunsForEventSchema>;

references/job-catalog/src/events.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,58 @@ client.defineJob({
7777
},
7878
});
7979

80+
client.defineJob({
81+
id: "cancel-runs-example",
82+
name: "Cancel Runs Example",
83+
version: "1.0.0",
84+
trigger: eventTrigger({
85+
name: "cancel.runs.example",
86+
}),
87+
run: async (payload, io, ctx) => {
88+
const event = await io.sendEvent("send-event", {
89+
name: "foo.bar",
90+
id: payload.id,
91+
payload: { payload, ctx },
92+
});
93+
94+
await io.wait("wait-1", 1); // 1 second
95+
96+
await io.runTask("cancel-runs", async () => {
97+
return await client.cancelRunsForEvent(event.id);
98+
});
99+
},
100+
});
101+
102+
client.defineJob({
103+
id: "foo-bar-example",
104+
name: "Foo Bar Example",
105+
version: "1.0.0",
106+
trigger: eventTrigger({
107+
name: "foo.bar",
108+
}),
109+
run: async (payload, io, ctx) => {
110+
await io.logger.info("Hello World", { ctx, payload });
111+
112+
await io.wait("wait-1", 10); // 10 seconds
113+
114+
await io.logger.info("Hello World 2", { ctx, payload });
115+
},
116+
});
117+
118+
client.defineJob({
119+
id: "foo-bar-example-2",
120+
name: "Foo Bar Example 2",
121+
version: "1.0.0",
122+
trigger: eventTrigger({
123+
name: "foo.bar",
124+
}),
125+
run: async (payload, io, ctx) => {
126+
await io.logger.info("Hello World", { ctx, payload });
127+
128+
await io.wait("wait-1", 10); // 10 seconds
129+
130+
await io.logger.info("Hello World 2", { ctx, payload });
131+
},
132+
});
133+
80134
createExpressServer(client);

0 commit comments

Comments
 (0)