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
11// Pub/Sub Lite is turned down for new projects (creates answer 403
12// PubSubLiteTurnedDown); only a project still allow-listed can run lifecycles.
13export const runLifecycle =
14 !process.env.FAST && process.env.GCP_TEST_PUBSUBLITE === "1";
15
16export const currentProject = GcpEnvironment.current.pipe(
17 Effect.map((env) => env.project),
18);
19export const region = "us-central1";
20export const zone = "us-central1-a";
21
22export const waitUntilGone = <E extends { readonly _tag: string }, R>(
23 get: Effect.Effect<unknown, E, R>,
24) =>
25 get.pipe(
26 Effect.as("found" as const),
27 Effect.catchIf(
28 (error): error is E & { readonly _tag: "NotFound" } =>
29 error._tag === "NotFound",
30 () => Effect.succeed("gone" as const),
31 ),
32 Effect.repeat({
33 schedule: Schedule.spaced("1 second"),
34 until: (status) => status === "gone",
35 times: 10,
36 }),
37 );