| 1 | import * as GCP from "@/GCP"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import { serveProbes } from "../../bindingHost.ts"; |
| 4 | |
| 5 | const job = (id: string) => |
| 6 | GCP.CloudScheduler.Job(id, { |
| 7 | schedule: "0 0 1 1 *", |
| 8 | timeZone: "UTC", |
| 9 | httpTarget: { uri: "https://example.com/", httpMethod: "GET" }, |
| 10 | }); |
| 11 | |
| 12 | /** Job {@link GCP.CloudScheduler.PauseJob} binds. */ |
| 13 | export const PausedJob = job("PausedJob"); |
| 14 | /** Job {@link GCP.CloudScheduler.ResumeJob} binds (paused by the test first). */ |
| 15 | export const ResumedJob = job("ResumedJob"); |
| 16 | /** Job {@link GCP.CloudScheduler.RunJob} binds. */ |
| 17 | export const RunJobTarget = job("RunJobTarget"); |
| 18 | |
| 19 | /** |
| 20 | * Effect-native Cloud Run service exercising every Cloud Scheduler binding as |
| 21 | * its own runtime service account. Deployed from {@link ../Bindings.test.ts}. |
| 22 | */ |
| 23 | export default class SchedulerBindingsHost extends GCP.Function<SchedulerBindingsHost>()( |
| 24 | "SchedulerBindingsHost", |
| 25 | { main: import.meta.url, invokerIamDisabled: true }, |
| 26 | Effect.gen(function* () { |
| 27 | const pauseJob = yield* GCP.CloudScheduler.PauseJob(PausedJob); |
| 28 | const resumeJob = yield* GCP.CloudScheduler.ResumeJob(ResumedJob); |
| 29 | const runJob = yield* GCP.CloudScheduler.RunJob(RunJobTarget); |
| 30 | |
| 31 | return { |
| 32 | fetch: serveProbes({ |
| 33 | pause: pauseJob(), |
| 34 | resume: resumeJob(), |
| 35 | run: runJob(), |
| 36 | }), |
| 37 | }; |
| 38 | }).pipe( |
| 39 | Effect.provide(GCP.CloudScheduler.PauseJobHttp), |
| 40 | Effect.provide(GCP.CloudScheduler.ResumeJobHttp), |
| 41 | Effect.provide(GCP.CloudScheduler.RunJobHttp), |
| 42 | ), |
| 43 | ) {} |