1import { GcpEnvironment } from "@/GCP/Environment";
2import { none as noGcpRetry } from "@distilled.cloud/gcp/Retry";
3import * as Effect from "effect/Effect";
4import { MinimumLogLevel } from "effect/References";
5import * as Schedule from "effect/Schedule";
6
7export const logLevel = Effect.provideService(
8 MinimumLogLevel,
9 process.env.DEBUG ? "Debug" : "Info",
10);
11
12export const currentProject = GcpEnvironment.current.pipe(
13 Effect.map((env) => env.project),
14);
15
16/**
17 * Data Labeling is shut down. Live GETs hang ~20s then return HTTP 502
18 * (`BadGateway`). Opt in with `GCP_TEST_DATALABELING=1` if the API
19 * returns.
20 */
21export const runLifecycle =
22 !process.env.FAST && process.env.GCP_TEST_DATALABELING === "1";
23
24export const probe = <A, E, R>(effect: Effect.Effect<A, E, R>) =>
25 effect.pipe(noGcpRetry);
26
27export const waitUntilGone = <A, E extends { readonly _tag: string }, R>(
28 get: Effect.Effect<A, E, R>,
29) =>
30 get.pipe(
31 noGcpRetry,
32 Effect.as("found" as const),
33 Effect.catchIf(
34 (error): error is E & { readonly _tag: "NotFound" | "BadGateway" } =>
35 error._tag === "NotFound" || error._tag === "BadGateway",
36 () => Effect.succeed("gone" as const),
37 ),
38 Effect.repeat({
39 schedule: Schedule.spaced("1 second"),
40 until: (status) => status === "gone",
41 times: 10,
42 }),
43 );