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

main
ts 23 lines 971 Bytes
Raw
1 import * as looker from "@distilled.cloud/gcp/looker_v1";
2 import * as Effect from "effect/Effect";
3 import { waitForOperation as waitForGcpOperation } from "../Operation.ts";
4
5 /**
6 * Wait for a Looker operation; instance backups take several minutes.
7 * ALREADY_EXISTS (code 6) counts as success (create race); with
8 * `notFoundOk`, so does NOT_FOUND (code 5, delete race) and an operation
9 * that is already gone.
10 */
11 export const waitForOperation = (operation: looker.Operation, options?: { notFoundOk?: boolean }) =>
12 waitForGcpOperation(operation, (name) => looker.getProjectsLocationsOperations({ name }), {
13 budget: "30 minutes",
14 interval: "10 seconds",
15 }).pipe(
16 Effect.catchIf(
17 (error) =>
18 (error._tag === "GCP.OperationFailed" &&
19 (error.code === 6 || (options?.notFoundOk === true && error.code === 5))) ||
20 (options?.notFoundOk === true && error._tag === "NotFound"),
21 () => Effect.succeed(operation),
22 ),
23 );