| 1 | import { GcpEnvironment } from "@/GCP/Environment"; |
| 2 | import type { GcpOpError } from "@distilled.cloud/gcp/datamigration_v1"; |
| 3 | import { NotFound } from "@distilled.cloud/gcp/datamigration_v1"; |
| 4 | import * as Effect from "effect/Effect"; |
| 5 | import { MinimumLogLevel } from "effect/References"; |
| 6 | import * as Schedule from "effect/Schedule"; |
| 7 | |
| 8 | export const logLevel = Effect.provideService( |
| 9 | MinimumLogLevel, |
| 10 | process.env.DEBUG ? "Debug" : "Info", |
| 11 | ); |
| 12 | |
| 13 | export const runSlowLifecycle = |
| 14 | !!process.env.GCP_TEST_SLOW && !process.env.FAST; |
| 15 | |
| 16 | export const currentProject = GcpEnvironment.current.pipe( |
| 17 | Effect.map((env) => env.project), |
| 18 | ); |
| 19 | |
| 20 | export 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 | ); |