The best way to control Claude Code, Codex and more from any computer or phone

main
ts 33 lines 1.2 KB
Raw
1 import * as alloydb from "@distilled.cloud/gcp/alloydb_v1";
2 import * as Effect from "effect/Effect";
3 import { waitForOperation as waitForLongRunning, type LongRunningOperation } from "../Operation.ts";
4
5 /** AlloyDB cluster and instance creates take 15–30 minutes. */
6 const OPERATION_BUDGET = "45 minutes";
7
8 /**
9 * Wait for a long-running operation. ALREADY_EXISTS (code 6) means a
10 * concurrent create won the race; reconcile observes the resource next.
11 */
12 export const waitForOperation = (operation: LongRunningOperation) =>
13 waitForLongRunning(operation, (name) => alloydb.getProjectsLocationsOperations({ name }), {
14 budget: OPERATION_BUDGET,
15 }).pipe(
16 Effect.catchIf(
17 (error) => error._tag === "GCP.OperationFailed" && error.code === 6,
18 () => Effect.succeed(operation),
19 ),
20 );
21
22 /**
23 * Wait for a delete operation. A vanished operation or NOT_FOUND (code 5)
24 * means the resource is already gone.
25 */
26 export const waitForDeleteOperation = (operation: LongRunningOperation) =>
27 waitForOperation(operation).pipe(
28 Effect.catchIf(
29 (error) =>
30 error._tag === "NotFound" || (error._tag === "GCP.OperationFailed" && error.code === 5),
31 () => Effect.succeed(operation),
32 ),
33 );