1import { GcpEnvironment } from "@/GCP/Environment";
2import type { GcpOpError } from "@distilled.cloud/gcp/datastream_v1";
3import { NotFound } from "@distilled.cloud/gcp/datastream_v1";
4import * as Effect from "effect/Effect";
5import { MinimumLogLevel } from "effect/References";
6import * as Schedule from "effect/Schedule";
7
8export 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.
14export const runLifecycle = !process.env.FAST;
15
16// Private connections peer a dedicated VPC and take 5-10 minutes to create
17// and delete.
18export const runSlowLifecycle =
19 !!process.env.GCP_TEST_SLOW && !process.env.FAST;
20
21export const currentProject = GcpEnvironment.current.pipe(
22 Effect.map((env) => env.project),
23);
24
25export const LOCATION = "us-central1";
26
27export 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 );