| 1 | import { GcpEnvironment } from "@/GCP/Environment"; |
| 2 | import type { GcpOpError } from "@distilled.cloud/gcp/datastream_v1"; |
| 3 | import { NotFound } from "@distilled.cloud/gcp/datastream_v1"; |
| 4 | import * as Effect from "effect/Effect"; |
| 5 | import { MinimumLogLevel } from "effect/References"; |
| 6 | import * as Schedule from "effect/Schedule"; |
| 7 | |
| 8 | export const logLevel = Effect.provideService( |
| 9 | MinimumLogLevel, |
| 10 | process.env.DEBUG ? "Debug" : "Info", |
| 11 | ); |
| 12 | |
| 13 | // Connection profiles and streams take 2-5 minutes end to end. |
| 14 | export const runLifecycle = !process.env.FAST; |
| 15 | |
| 16 | // Private connections peer a dedicated VPC and take 5-10 minutes to create |
| 17 | // and delete. |
| 18 | export const runSlowLifecycle = |
| 19 | !!process.env.GCP_TEST_SLOW && !process.env.FAST; |
| 20 | |
| 21 | export const currentProject = GcpEnvironment.current.pipe( |
| 22 | Effect.map((env) => env.project), |
| 23 | ); |
| 24 | |
| 25 | export const LOCATION = "us-central1"; |
| 26 | |
| 27 | export const waitUntilGone = <A, E extends { readonly _tag: string }, R>( |
| 28 | get: Effect.Effect<A, E | NotFound | GcpOpError, R>, |
| 29 | ) => |
| 30 | get.pipe( |
| 31 | Effect.as("found" as const), |
| 32 | Effect.catchIf( |
| 33 | (error): error is NotFound => error._tag === "NotFound", |
| 34 | () => Effect.succeed("gone" as const), |
| 35 | ), |
| 36 | Effect.repeat({ |
| 37 | schedule: Schedule.spaced("2 seconds"), |
| 38 | until: (status) => status === "gone", |
| 39 | times: 10, |
| 40 | }), |
| 41 | ); |