| 1 | import { GcpEnvironment } from "@/GCP/Environment"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import { MinimumLogLevel } from "effect/References"; |
| 4 | import * as Schedule from "effect/Schedule"; |
| 5 | |
| 6 | export 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. |
| 13 | export const runLifecycle = |
| 14 | !process.env.FAST && process.env.GCP_TEST_PUBSUBLITE === "1"; |
| 15 | |
| 16 | export const currentProject = GcpEnvironment.current.pipe( |
| 17 | Effect.map((env) => env.project), |
| 18 | ); |
| 19 | export const region = "us-central1"; |
| 20 | export const zone = "us-central1-a"; |
| 21 | |
| 22 | export 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 | ); |