| 1 | import * as GCP from "@/GCP"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import { serveProbes } from "../../bindingHost.ts"; |
| 4 | |
| 5 | /** Queue the binding is granted on (roles/cloudtasks.enqueuer). */ |
| 6 | export const Jobs = GCP.CloudTasks.Queue("Jobs", { location: "us-central1" }); |
| 7 | |
| 8 | /** Target of the enqueued task; scheduled a day out so it never dispatches. */ |
| 9 | export const TASK_URL = "https://example.com/alchemy-binding"; |
| 10 | |
| 11 | /** |
| 12 | * Effect-native Cloud Run service exercising every Cloud Tasks binding as |
| 13 | * its own runtime service account. Deployed from {@link ../Bindings.test.ts}. |
| 14 | */ |
| 15 | export default class CloudTasksBindingsHost extends GCP.Function<CloudTasksBindingsHost>()( |
| 16 | "CloudTasksBindingsHost", |
| 17 | { main: import.meta.url, invokerIamDisabled: true }, |
| 18 | Effect.gen(function* () { |
| 19 | const createTask = yield* GCP.CloudTasks.CreateTask(Jobs); |
| 20 | |
| 21 | return { |
| 22 | fetch: serveProbes({ |
| 23 | createTask: Effect.gen(function* () { |
| 24 | const scheduleTime = yield* Effect.sync(() => |
| 25 | new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(), |
| 26 | ); |
| 27 | return yield* createTask({ |
| 28 | body: { |
| 29 | task: { |
| 30 | scheduleTime, |
| 31 | httpRequest: { |
| 32 | url: TASK_URL, |
| 33 | httpMethod: "POST", |
| 34 | body: btoa(JSON.stringify({ id: "1" })), |
| 35 | }, |
| 36 | }, |
| 37 | }, |
| 38 | }); |
| 39 | }), |
| 40 | }), |
| 41 | }; |
| 42 | }).pipe(Effect.provide(GCP.CloudTasks.CreateTaskHttp)), |
| 43 | ) {} |