| 1 | import * as GCP from "@/GCP"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as HttpServerResponse from "effect/http/HttpServerResponse"; |
| 4 | |
| 5 | /** |
| 6 | * Effect-native Cloud Run Service that binds Memorystore over Direct VPC |
| 7 | * egress. Gated by `GCP_TEST_REDIS=1` — instance create takes minutes. |
| 8 | */ |
| 9 | export default class BoundRedisService extends GCP.Function<BoundRedisService>()( |
| 10 | "BoundRedisService", |
| 11 | { |
| 12 | main: import.meta.url, |
| 13 | location: "us-central1", |
| 14 | invokerIamDisabled: true, |
| 15 | template: { |
| 16 | vpcAccess: { |
| 17 | egress: "PRIVATE_RANGES_ONLY", |
| 18 | networkInterfaces: [{ network: "default", subnetwork: "default" }], |
| 19 | }, |
| 20 | }, |
| 21 | }, |
| 22 | Effect.gen(function* () { |
| 23 | const cache = yield* GCP.Redis.Instance("Cache", { memorySizeGb: 1 }); |
| 24 | const redis = yield* GCP.Redis.ReadWriteRedis(cache); |
| 25 | |
| 26 | return { |
| 27 | fetch: Effect.gen(function* () { |
| 28 | yield* redis.set("probe", "ok").pipe(Effect.orDie); |
| 29 | const cached = yield* redis.get("probe").pipe(Effect.orDie); |
| 30 | return yield* HttpServerResponse.json({ redis: cached }); |
| 31 | }), |
| 32 | }; |
| 33 | }).pipe(Effect.provide(GCP.Redis.ReadWriteRedisHttp)), |
| 34 | ) {} |