1import { GcpEnvironment } from "@/GCP/Environment";
2import * as Effect from "effect/Effect";
3import { MinimumLogLevel } from "effect/References";
4import * as Schedule from "effect/Schedule";
5
6export const logLevel = Effect.provideService(
7 MinimumLogLevel,
8 process.env.DEBUG ? "Debug" : "Info",
9);
10
11export const currentProject = GcpEnvironment.current.pipe(
12 Effect.map((env) => env.project),
13);
14
15export const waitUntilGone = <E extends { readonly _tag: string }, R>(
16 get: Effect.Effect<unknown, E, R>,
17) =>
18 get.pipe(
19 Effect.as("found" as const),
20 Effect.catchIf(
21 (error) => error._tag === "NotFound",
22 () => Effect.succeed("gone" as const),
23 ),
24 Effect.repeat({
25 schedule: Schedule.spaced("1 second"),
26 until: (status) => status === "gone",
27 times: 10,
28 }),
29 );