1import { GcpEnvironment } from "@/GCP/Environment";
2import type { GcpOpError } from "@distilled.cloud/gcp/datamigration_v1";
3import { NotFound } from "@distilled.cloud/gcp/datamigration_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
13export const runSlowLifecycle =
14 !!process.env.GCP_TEST_SLOW && !process.env.FAST;
15
16export const currentProject = GcpEnvironment.current.pipe(
17 Effect.map((env) => env.project),
18);
19
20export const waitUntilGone = <A, E extends { readonly _tag: string }, R>(
21 get: Effect.Effect<A, E | NotFound | GcpOpError, R>,
22) =>
23 get.pipe(
24 Effect.as("found" as const),
25 Effect.catchIf(
26 (error): error is NotFound => error._tag === "NotFound",
27 () => Effect.succeed("gone" as const),
28 ),
29 Effect.repeat({
30 schedule: Schedule.spaced("2 seconds"),
31 until: (status) => status === "gone",
32 times: 10,
33 }),
34 );