Added tests and refactored response to use camelCase
This commit is contained in:
@@ -62,8 +62,8 @@ export class CancelRunsForEventService {
|
||||
}
|
||||
|
||||
return {
|
||||
cancelled_run_ids: cancelledRunIds,
|
||||
failed_to_cancel_run_ids: failedToCancelRunIds,
|
||||
cancelledRunIds: cancelledRunIds,
|
||||
failedToCancelRunIds: failedToCancelRunIds,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@ description: "The `cancelRunsForEvent()` instance method will cancel all the job
|
||||
|
||||
<ResponseField type="object">
|
||||
<Expandable title="properties" defaultOpen>
|
||||
<ResponseField name="cancelled_run_ids" type="array" required>
|
||||
<ResponseField name="cancelledRunIds" type="array" required>
|
||||
List of Job Run IDs that are cancelled.
|
||||
</ResponseField>
|
||||
<ResponseField name="failed_to_cancel_run_ids" type="array" required>
|
||||
<ResponseField name="failedToCancelRunIds" type="array" required>
|
||||
List of Job Run IDs that have failed to be cancelled.
|
||||
</ResponseField>
|
||||
</Expandable>
|
||||
@@ -32,10 +32,11 @@ const event = client.sendEvent({
|
||||
name: "test.job",
|
||||
});
|
||||
|
||||
const res = client.cancelRunsForEvent(event.id);
|
||||
// Some time later...
|
||||
const res = await client.cancelRunsForEvent(event.id);
|
||||
|
||||
console.log(res.cancelled_run_ids);
|
||||
console.log(res.failed_to_cancel_run_ids);
|
||||
console.log(res.cancelledRunIds);
|
||||
console.log(res.failedToCancelRunIds);
|
||||
```
|
||||
|
||||
</RequestExample>
|
||||
|
||||
@@ -28,8 +28,8 @@ export const GetEventSchema = z.object({
|
||||
export type GetEvent = z.infer<typeof GetEventSchema>;
|
||||
|
||||
export const CancelRunsForEventSchema = z.object({
|
||||
cancelled_run_ids: z.array(z.string()),
|
||||
failed_to_cancel_run_ids: z.array(z.string()),
|
||||
cancelledRunIds: z.array(z.string()),
|
||||
failedToCancelRunIds: z.array(z.string()),
|
||||
});
|
||||
|
||||
export type CancelRunsForEvent = z.infer<typeof CancelRunsForEventSchema>;
|
||||
|
||||
@@ -77,4 +77,58 @@ client.defineJob({
|
||||
},
|
||||
});
|
||||
|
||||
client.defineJob({
|
||||
id: "cancel-runs-example",
|
||||
name: "Cancel Runs Example",
|
||||
version: "1.0.0",
|
||||
trigger: eventTrigger({
|
||||
name: "cancel.runs.example",
|
||||
}),
|
||||
run: async (payload, io, ctx) => {
|
||||
const event = await io.sendEvent("send-event", {
|
||||
name: "foo.bar",
|
||||
id: payload.id,
|
||||
payload: { payload, ctx },
|
||||
});
|
||||
|
||||
await io.wait("wait-1", 1); // 1 second
|
||||
|
||||
await io.runTask("cancel-runs", async () => {
|
||||
return await client.cancelRunsForEvent(event.id);
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
client.defineJob({
|
||||
id: "foo-bar-example",
|
||||
name: "Foo Bar Example",
|
||||
version: "1.0.0",
|
||||
trigger: eventTrigger({
|
||||
name: "foo.bar",
|
||||
}),
|
||||
run: async (payload, io, ctx) => {
|
||||
await io.logger.info("Hello World", { ctx, payload });
|
||||
|
||||
await io.wait("wait-1", 10); // 10 seconds
|
||||
|
||||
await io.logger.info("Hello World 2", { ctx, payload });
|
||||
},
|
||||
});
|
||||
|
||||
client.defineJob({
|
||||
id: "foo-bar-example-2",
|
||||
name: "Foo Bar Example 2",
|
||||
version: "1.0.0",
|
||||
trigger: eventTrigger({
|
||||
name: "foo.bar",
|
||||
}),
|
||||
run: async (payload, io, ctx) => {
|
||||
await io.logger.info("Hello World", { ctx, payload });
|
||||
|
||||
await io.wait("wait-1", 10); // 10 seconds
|
||||
|
||||
await io.logger.info("Hello World 2", { ctx, payload });
|
||||
},
|
||||
});
|
||||
|
||||
createExpressServer(client);
|
||||
|
||||
Reference in New Issue
Block a user