@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 689 lines 21.9 KB
Raw
1 import * as compute from "@distilled.cloud/gcp/compute_v1";
2 import { Unowned } from "alchemy/AdoptPolicy";
3 import { isResolved } from "alchemy/Diff";
4 import { createPhysicalName } from "alchemy/PhysicalName";
5 import * as Provider from "alchemy/Provider";
6 import { Resource } from "alchemy/Resource";
7 import * as Data from "effect/Data";
8 import * as Effect from "effect/Effect";
9 import * as Schedule from "effect/Schedule";
10 import * as Stream from "effect/Stream";
11 import { GcpEnvironment } from "../Environment.ts";
12 import { alchemyLabelKeys, createInternalLabels, hasAlchemyLabels } from "../Labels.ts";
13 import type { Providers } from "../Providers.ts";
14 import type {
15 GrpcHealthCheck,
16 HealthCheckLogConfig,
17 HealthCheckPortSpecification,
18 HealthCheckProxyHeader,
19 HealthCheckType,
20 Http2HealthCheck,
21 HttpHealthCheck,
22 HttpsHealthCheck,
23 SslHealthCheck,
24 TcpHealthCheck,
25 } from "./HealthCheck.ts";
26 import { waitRegionOperation } from "./operations.ts";
27
28 const DEFAULT_CHECK_INTERVAL = 5;
29 const DEFAULT_TIMEOUT = 5;
30 const DEFAULT_HEALTHY = 2;
31 const DEFAULT_UNHEALTHY = 2;
32 const MAX_NAME_LENGTH = 63;
33
34 export type RegionHealthCheckProps = {
35 /**
36 * Health check name (RFC1035, 1-63 chars). If omitted, a unique name is
37 * generated from the stack, stage, and logical id. Changing it replaces
38 * the resource.
39 */
40 healthCheckName?: string;
41 /**
42 * Region the health check lives in. Immutable — changing it replaces
43 * the resource. `US-CENTRAL1` is accepted and normalized to
44 * `us-central1`.
45 * @default the stack's GCP region (`GCP.Region`, else the profile region, else `us-central1`)
46 */
47 region?: string;
48 /**
49 * Optional description. Alchemy ownership is stored in a `[alchemy …]`
50 * prefix so `list` / nuke can find resources (Compute HealthCheck has no
51 * labels field).
52 */
53 description?: string;
54 /**
55 * How often to probe, in seconds.
56 * @default 5
57 */
58 checkIntervalSec?: number;
59 /**
60 * Probe timeout in seconds. Must be ≤ `checkIntervalSec`.
61 * @default 5
62 */
63 timeoutSec?: number;
64 /**
65 * Consecutive successes before an instance is healthy.
66 * @default 2
67 */
68 healthyThreshold?: number;
69 /**
70 * Consecutive failures before an instance is unhealthy.
71 * @default 2
72 */
73 unhealthyThreshold?: number;
74 /**
75 * Protocol. Inferred from the nested `*HealthCheck` block when omitted.
76 * Changing type replaces the resource.
77 * @default "HTTP"
78 */
79 type?: HealthCheckType;
80 /** HTTP probe. Used when `type` is `HTTP` (the default). */
81 httpHealthCheck?: HttpHealthCheck;
82 /** HTTPS probe. */
83 httpsHealthCheck?: HttpsHealthCheck;
84 /** HTTP/2 probe. */
85 http2HealthCheck?: Http2HealthCheck;
86 /** TCP probe. */
87 tcpHealthCheck?: TcpHealthCheck;
88 /** SSL probe. */
89 sslHealthCheck?: SslHealthCheck;
90 /** gRPC probe. */
91 grpcHealthCheck?: GrpcHealthCheck;
92 /** gRPC-with-TLS probe. */
93 grpcTlsHealthCheck?: GrpcHealthCheck;
94 /** Health-check logging. */
95 logConfig?: HealthCheckLogConfig;
96 };
97
98 export type RegionHealthCheck = Resource<
99 "GCP.Compute.RegionHealthCheck",
100 RegionHealthCheckProps,
101 {
102 /** Health check name. */
103 healthCheckName: string;
104 /** Project id. */
105 project: string;
106 /** Region short name (`us-central1`). */
107 region: string;
108 /** Protocol. */
109 type: HealthCheckType;
110 /** User description with the Alchemy ownership prefix stripped. */
111 description: string | undefined;
112 /** Probe interval in seconds. */
113 checkIntervalSec: number;
114 /** Probe timeout in seconds. */
115 timeoutSec: number;
116 /** Consecutive successes before healthy. */
117 healthyThreshold: number;
118 /** Consecutive failures before unhealthy. */
119 unhealthyThreshold: number;
120 /** HTTP probe, if this is an HTTP health check. */
121 httpHealthCheck: HttpHealthCheck | undefined;
122 /** HTTPS probe, if this is an HTTPS health check. */
123 httpsHealthCheck: HttpsHealthCheck | undefined;
124 /** HTTP/2 probe, if this is an HTTP/2 health check. */
125 http2HealthCheck: Http2HealthCheck | undefined;
126 /** TCP probe, if this is a TCP health check. */
127 tcpHealthCheck: TcpHealthCheck | undefined;
128 /** SSL probe, if this is an SSL health check. */
129 sslHealthCheck: SslHealthCheck | undefined;
130 /** gRPC probe, if this is a gRPC health check. */
131 grpcHealthCheck: GrpcHealthCheck | undefined;
132 /** gRPC-with-TLS probe, if this is a GRPC_WITH_TLS health check. */
133 grpcTlsHealthCheck: GrpcHealthCheck | undefined;
134 /** Logging configuration. */
135 logConfig: HealthCheckLogConfig | undefined;
136 /** Server-defined URL. */
137 selfLink: string | undefined;
138 /** Server-assigned numeric id. */
139 healthCheckId: string | undefined;
140 /** RFC3339 creation timestamp. */
141 creationTimestamp: string | undefined;
142 /** Resource kind. */
143 kind: string | undefined;
144 },
145 never,
146 Providers
147 >;
148
149 /**
150 * A regional Compute Engine health check.
151 *
152 * Health checks probe backends for load balancing and managed-instance-group
153 * autohealing. This resource maps to the regional `regionHealthChecks`
154 * collection (the global `healthChecks` resource is
155 * `GCP.Compute.HealthCheck`). Compute HealthCheck has no labels field —
156 * Alchemy ownership is stored in the description so nuke can find leaked
157 * checks.
158 *
159 * Changing `healthCheckName`, `region`, or `type` replaces the resource.
160 *
161 * ### Creating a Region Health Check
162 * **Example:** Generated name (HTTP on port 80)
163 * ```typescript
164 * const check = yield* GCP.Compute.RegionHealthCheck("api", {});
165 * ```
166 *
167 * **Example:** HTTP path and thresholds
168 * ```typescript
169 * const check = yield* GCP.Compute.RegionHealthCheck("api", {
170 * region: "us-central1",
171 * description: "frontend /health",
172 * checkIntervalSec: 10,
173 * timeoutSec: 5,
174 * httpHealthCheck: { port: 80, requestPath: "/health" },
175 * });
176 * ```
177 *
178 * **Example:** TCP health check
179 * ```typescript
180 * const check = yield* GCP.Compute.RegionHealthCheck("tcp", {
181 * type: "TCP",
182 * tcpHealthCheck: { port: 8080 },
183 * });
184 * ```
185 *
186 * @resource
187 * @category Compute
188 */
189 export const RegionHealthCheck = Resource<RegionHealthCheck>("GCP.Compute.RegionHealthCheck");
190
191 export class RegionHealthCheckNotResolved extends Data.TaggedError(
192 "GCP.Compute.RegionHealthCheckNotResolved",
193 )<{
194 healthCheckName: string;
195 region: string;
196 }> {}
197
198 const lastSegment = (value: string | undefined): string => {
199 if (value === undefined || value.length === 0) return "";
200 const parts = value.split("/").filter((part) => part.length > 0);
201 return parts[parts.length - 1] ?? value;
202 };
203
204 const normalizeRegion = (region: string | undefined, defaultRegion: string) =>
205 lastSegment(region ?? defaultRegion).toLowerCase();
206
207 const rfc1035 = (name: string): string => {
208 let next = name
209 .toLowerCase()
210 .replace(/[^a-z0-9-]/g, "-")
211 .replace(/-+/g, "-")
212 .replace(/^-+/, "")
213 .replace(/-+$/, "");
214 if (!/^[a-z]/.test(next)) {
215 next = `h${next}`;
216 }
217 next = next.slice(0, MAX_NAME_LENGTH).replace(/-+$/, "");
218 return next.length > 0 ? next : "healthcheck";
219 };
220
221 const toName = (id: string, name: string | undefined, existing?: string) =>
222 Effect.gen(function* () {
223 if (name !== undefined) return name;
224 if (existing !== undefined) return existing;
225 return rfc1035(
226 yield* createPhysicalName({
227 id,
228 maxLength: MAX_NAME_LENGTH,
229 lowercase: true,
230 }),
231 );
232 });
233
234 const inferType = (props: RegionHealthCheckProps): HealthCheckType => {
235 if (props.type) return props.type;
236 if (props.httpsHealthCheck) return "HTTPS";
237 if (props.http2HealthCheck) return "HTTP2";
238 if (props.sslHealthCheck) return "SSL";
239 if (props.tcpHealthCheck) return "TCP";
240 if (props.grpcHealthCheck) return "GRPC";
241 if (props.grpcTlsHealthCheck) return "GRPC_WITH_TLS";
242 return "HTTP";
243 };
244
245 const encodeDescription = (
246 labels: Record<string, string>,
247 description: string | undefined,
248 ): string => {
249 const marker = `[alchemy ${alchemyLabelKeys.stack}=${labels[alchemyLabelKeys.stack]} ${alchemyLabelKeys.stage}=${labels[alchemyLabelKeys.stage]} ${alchemyLabelKeys.id}=${labels[alchemyLabelKeys.id]}]`;
250 return description ? `${marker}\n${description}` : marker;
251 };
252
253 const parseDescription = (
254 description: string | undefined,
255 ): {
256 labels: Record<string, string>;
257 description: string | undefined;
258 } => {
259 if (!description?.startsWith("[alchemy ")) {
260 return { labels: {}, description };
261 }
262 const end = description.indexOf("]");
263 if (end < 0) return { labels: {}, description };
264 const labels: Record<string, string> = {};
265 for (const part of description.slice("[alchemy ".length, end).split(/\s+/)) {
266 const eq = part.indexOf("=");
267 if (eq > 0) {
268 labels[part.slice(0, eq)] = part.slice(eq + 1);
269 }
270 }
271 const rest = description.slice(end + 1).replace(/^\n/, "");
272 return { labels, description: rest.length > 0 ? rest : undefined };
273 };
274
275 const hasOwnershipMarker = (description: string | undefined) =>
276 Object.keys(parseDescription(description).labels).some((key) => key.startsWith("alchemy-"));
277
278 const protocolBody = (
279 type: HealthCheckType,
280 props: RegionHealthCheckProps,
281 ): Pick<
282 compute.HealthCheck,
283 | "httpHealthCheck"
284 | "httpsHealthCheck"
285 | "http2HealthCheck"
286 | "tcpHealthCheck"
287 | "sslHealthCheck"
288 | "grpcHealthCheck"
289 | "grpcTlsHealthCheck"
290 > => {
291 switch (type) {
292 case "HTTPS":
293 return {
294 httpsHealthCheck: {
295 port: 443,
296 requestPath: "/",
297 ...props.httpsHealthCheck,
298 },
299 };
300 case "HTTP2":
301 return {
302 http2HealthCheck: {
303 port: 443,
304 requestPath: "/",
305 ...props.http2HealthCheck,
306 },
307 };
308 case "TCP":
309 return { tcpHealthCheck: { port: 80, ...props.tcpHealthCheck } };
310 case "SSL":
311 return { sslHealthCheck: { port: 443, ...props.sslHealthCheck } };
312 case "GRPC":
313 return { grpcHealthCheck: { port: 443, ...props.grpcHealthCheck } };
314 case "GRPC_WITH_TLS":
315 return {
316 grpcTlsHealthCheck: { port: 443, ...props.grpcTlsHealthCheck },
317 };
318 default:
319 return {
320 httpHealthCheck: {
321 port: 80,
322 requestPath: "/",
323 ...props.httpHealthCheck,
324 },
325 };
326 }
327 };
328
329 const toBody = (
330 healthCheckName: string,
331 props: RegionHealthCheckProps,
332 ownership: Record<string, string>,
333 ): compute.HealthCheck => {
334 const type = inferType(props);
335 return {
336 name: healthCheckName,
337 description: encodeDescription(ownership, props.description),
338 checkIntervalSec: props.checkIntervalSec ?? DEFAULT_CHECK_INTERVAL,
339 timeoutSec: props.timeoutSec ?? DEFAULT_TIMEOUT,
340 healthyThreshold: props.healthyThreshold ?? DEFAULT_HEALTHY,
341 unhealthyThreshold: props.unhealthyThreshold ?? DEFAULT_UNHEALTHY,
342 type,
343 logConfig: { enable: props.logConfig?.enable === true },
344 ...protocolBody(type, props),
345 };
346 };
347
348 const asType = (type: string | undefined): HealthCheckType => {
349 switch (type) {
350 case "TCP":
351 case "SSL":
352 case "HTTP":
353 case "HTTPS":
354 case "HTTP2":
355 case "GRPC":
356 case "GRPC_WITH_TLS":
357 return type;
358 default:
359 return "HTTP";
360 }
361 };
362
363 const asPortSpecification = (
364 value: string | undefined,
365 ): HealthCheckPortSpecification | undefined => {
366 switch (value) {
367 case "USE_FIXED_PORT":
368 case "USE_NAMED_PORT":
369 case "USE_SERVING_PORT":
370 return value;
371 default:
372 return undefined;
373 }
374 };
375
376 const asProxyHeader = (value: string | undefined): HealthCheckProxyHeader | undefined => {
377 switch (value) {
378 case "NONE":
379 case "PROXY_V1":
380 return value;
381 default:
382 return undefined;
383 }
384 };
385
386 const toHttpProbe = (
387 check: compute.HTTPHealthCheck | compute.HTTPSHealthCheck | compute.HTTP2HealthCheck | undefined,
388 ): HttpHealthCheck | undefined => {
389 if (check === undefined) return undefined;
390 return {
391 host: check.host,
392 port: check.port,
393 portName: check.portName,
394 portSpecification: asPortSpecification(check.portSpecification),
395 requestPath: check.requestPath,
396 response: check.response,
397 proxyHeader: asProxyHeader(check.proxyHeader),
398 };
399 };
400
401 const toTcpProbe = (
402 check: compute.TCPHealthCheck | compute.SSLHealthCheck | undefined,
403 ): TcpHealthCheck | undefined => {
404 if (check === undefined) return undefined;
405 return {
406 port: check.port,
407 portName: check.portName,
408 portSpecification: asPortSpecification(check.portSpecification),
409 request: check.request,
410 response: check.response,
411 proxyHeader: asProxyHeader(check.proxyHeader),
412 };
413 };
414
415 const toGrpcProbe = (
416 check: compute.GRPCHealthCheck | compute.GRPCTLSHealthCheck | undefined,
417 ): GrpcHealthCheck | undefined => {
418 if (check === undefined) return undefined;
419 return {
420 port: check.port,
421 portName: "portName" in check ? check.portName : undefined,
422 portSpecification: asPortSpecification(check.portSpecification),
423 grpcServiceName: check.grpcServiceName,
424 };
425 };
426
427 const toAttrs = (check: compute.HealthCheck, project: string): RegionHealthCheck["Attributes"] => {
428 const parsed = parseDescription(check.description);
429 return {
430 healthCheckName: check.name ?? check.id ?? "",
431 project,
432 region: lastSegment(check.region).toLowerCase(),
433 type: asType(check.type),
434 description: parsed.description,
435 checkIntervalSec: check.checkIntervalSec ?? DEFAULT_CHECK_INTERVAL,
436 timeoutSec: check.timeoutSec ?? DEFAULT_TIMEOUT,
437 healthyThreshold: check.healthyThreshold ?? DEFAULT_HEALTHY,
438 unhealthyThreshold: check.unhealthyThreshold ?? DEFAULT_UNHEALTHY,
439 httpHealthCheck: toHttpProbe(check.httpHealthCheck),
440 httpsHealthCheck: toHttpProbe(check.httpsHealthCheck),
441 http2HealthCheck: toHttpProbe(check.http2HealthCheck),
442 tcpHealthCheck: toTcpProbe(check.tcpHealthCheck),
443 sslHealthCheck: toTcpProbe(check.sslHealthCheck),
444 grpcHealthCheck: toGrpcProbe(check.grpcHealthCheck),
445 grpcTlsHealthCheck: toGrpcProbe(check.grpcTlsHealthCheck),
446 logConfig: check.logConfig === undefined ? undefined : { enable: check.logConfig.enable },
447 selfLink: check.selfLink,
448 healthCheckId: check.id,
449 creationTimestamp: check.creationTimestamp,
450 kind: check.kind,
451 };
452 };
453
454 const subsetEqual = (
455 observed: Record<string, unknown> | undefined,
456 desired: Record<string, unknown> | undefined,
457 ): boolean => {
458 if (desired === undefined) return true;
459 const current = observed ?? {};
460 for (const [key, value] of Object.entries(desired)) {
461 if (value === undefined) continue;
462 if (current[key] !== value) return false;
463 }
464 return true;
465 };
466
467 const asRecord = (value: object | undefined): Record<string, unknown> | undefined => {
468 if (value === undefined) return undefined;
469 const record: Record<string, unknown> = {};
470 for (const [key, entry] of Object.entries(value)) {
471 record[key] = entry;
472 }
473 return record;
474 };
475
476 const protocolConfig = (check: compute.HealthCheck, type: HealthCheckType) => {
477 switch (type) {
478 case "HTTPS":
479 return check.httpsHealthCheck;
480 case "HTTP2":
481 return check.http2HealthCheck;
482 case "TCP":
483 return check.tcpHealthCheck;
484 case "SSL":
485 return check.sslHealthCheck;
486 case "GRPC":
487 return check.grpcHealthCheck;
488 case "GRPC_WITH_TLS":
489 return check.grpcTlsHealthCheck;
490 default:
491 return check.httpHealthCheck;
492 }
493 };
494
495 const needsUpdate = (current: compute.HealthCheck, desired: compute.HealthCheck) => {
496 const currentType = asType(current.type);
497 const desiredType = asType(desired.type);
498 if (currentType !== desiredType) return true;
499 if (
500 (current.checkIntervalSec ?? DEFAULT_CHECK_INTERVAL) !==
501 (desired.checkIntervalSec ?? DEFAULT_CHECK_INTERVAL)
502 ) {
503 return true;
504 }
505 if ((current.timeoutSec ?? DEFAULT_TIMEOUT) !== (desired.timeoutSec ?? DEFAULT_TIMEOUT)) {
506 return true;
507 }
508 if (
509 (current.healthyThreshold ?? DEFAULT_HEALTHY) !== (desired.healthyThreshold ?? DEFAULT_HEALTHY)
510 ) {
511 return true;
512 }
513 if (
514 (current.unhealthyThreshold ?? DEFAULT_UNHEALTHY) !==
515 (desired.unhealthyThreshold ?? DEFAULT_UNHEALTHY)
516 ) {
517 return true;
518 }
519 if ((current.description ?? "") !== (desired.description ?? "")) return true;
520 if ((current.logConfig?.enable === true) !== (desired.logConfig?.enable === true)) {
521 return true;
522 }
523 return !subsetEqual(
524 asRecord(protocolConfig(current, desiredType)),
525 asRecord(protocolConfig(desired, desiredType)),
526 );
527 };
528
529 const getByName = (project: string, region: string, healthCheck: string) =>
530 compute
531 .getRegionHealthChecks({ project, region, healthCheck })
532 .pipe(Effect.catchTag("NotFound", () => Effect.undefined));
533
534 const awaitResource = (project: string, region: string, healthCheckName: string) =>
535 getByName(project, region, healthCheckName).pipe(
536 Effect.repeat({
537 schedule: Schedule.spaced("1 second"),
538 until: (check) => check !== undefined,
539 times: 8,
540 }),
541 );
542
543 export const RegionHealthCheckProvider = () =>
544 Provider.succeed(RegionHealthCheck, {
545 stables: [
546 "healthCheckName",
547 "project",
548 "region",
549 "healthCheckId",
550 "selfLink",
551 "creationTimestamp",
552 ],
553
554 diff: Effect.fn(function* ({ news, olds, output }) {
555 if (!isResolved(news)) return undefined;
556 const env = yield* GcpEnvironment.current;
557 const previousName = olds?.healthCheckName ?? output?.healthCheckName;
558 const nextName = news.healthCheckName;
559 const previousRegion = normalizeRegion(olds?.region ?? output?.region, env.region);
560 const nextRegion = normalizeRegion(news.region ?? (previousRegion || env.region), env.region);
561 const nameChanged =
562 previousName !== undefined && nextName !== undefined && previousName !== nextName;
563 const regionChanged = previousRegion.length > 0 && previousRegion !== nextRegion;
564 if (nameChanged || regionChanged) {
565 return {
566 action: "replace" as const,
567 deleteFirst: !nameChanged || nextName === undefined || nextName === previousName,
568 };
569 }
570 const previousType = (olds !== undefined ? inferType(olds) : undefined) ?? output?.type;
571 const nextType = inferType(news);
572 if (previousType !== undefined && previousType !== nextType) {
573 return {
574 action: "replace" as const,
575 deleteFirst:
576 previousName !== undefined && (nextName === undefined || nextName === previousName),
577 };
578 }
579 return undefined;
580 }),
581
582 read: Effect.fn(function* ({ id, olds, output }) {
583 const env = yield* GcpEnvironment.current;
584 const healthCheckName = yield* toName(id, olds?.healthCheckName, output?.healthCheckName);
585 const region = normalizeRegion(olds?.region ?? output?.region, env.region);
586 const existing = yield* getByName(env.project, region, healthCheckName);
587 if (existing === undefined) return undefined;
588 const attrs = toAttrs(existing, env.project);
589 const { labels } = parseDescription(existing.description);
590 return (yield* hasAlchemyLabels(id, labels)) ? attrs : Unowned(attrs);
591 }),
592
593 list: () =>
594 Effect.gen(function* () {
595 const env = yield* GcpEnvironment.current;
596 const pages = yield* compute.aggregatedListHealthChecks
597 .pages({
598 project: env.project,
599 maxResults: 500,
600 returnPartialSuccess: true,
601 })
602 .pipe(Stream.runCollect);
603 return Array.from(pages).flatMap((page) =>
604 Object.values(page.items ?? {}).flatMap((scoped) =>
605 (scoped?.healthChecks ?? [])
606 .filter(
607 (check) =>
608 lastSegment(check.region).length > 0 && hasOwnershipMarker(check.description),
609 )
610 .map((check) => toAttrs(check, env.project)),
611 ),
612 );
613 }),
614
615 reconcile: Effect.fn(function* ({ id, news, output }) {
616 const env = yield* GcpEnvironment.current;
617 const healthCheckName = yield* toName(id, news.healthCheckName, output?.healthCheckName);
618 const region = normalizeRegion(news.region ?? output?.region, env.region);
619 const ownership = yield* createInternalLabels(id);
620 const desired = toBody(healthCheckName, news, ownership);
621
622 let current = yield* getByName(env.project, region, healthCheckName);
623
624 if (current === undefined) {
625 yield* compute
626 .insertRegionHealthChecks({
627 project: env.project,
628 region,
629 body: desired,
630 })
631 .pipe(
632 Effect.flatMap((operation) => waitRegionOperation(env.project, region, operation)),
633 Effect.catchTag("Conflict", () => Effect.undefined),
634 );
635 current = yield* awaitResource(env.project, region, healthCheckName);
636 }
637
638 if (current === undefined) {
639 return yield* new RegionHealthCheckNotResolved({
640 healthCheckName,
641 region,
642 });
643 }
644
645 if (needsUpdate(current, desired)) {
646 yield* compute
647 .patchRegionHealthChecks({
648 project: env.project,
649 region,
650 healthCheck: healthCheckName,
651 body: desired,
652 })
653 .pipe(Effect.flatMap((operation) => waitRegionOperation(env.project, region, operation)));
654 current = yield* getByName(env.project, region, healthCheckName);
655 if (current === undefined) {
656 return yield* new RegionHealthCheckNotResolved({
657 healthCheckName,
658 region,
659 });
660 }
661 }
662
663 return toAttrs(current, env.project);
664 }),
665
666 delete: Effect.fn(function* ({ output }) {
667 const env = yield* GcpEnvironment.current;
668 const region = normalizeRegion(output.region, env.region);
669 const operation = yield* compute
670 .deleteRegionHealthChecks({
671 project: env.project,
672 region,
673 healthCheck: output.healthCheckName,
674 })
675 .pipe(
676 Effect.retry({
677 while: (error) => error._tag === "Conflict",
678 schedule: Schedule.spaced("2 seconds"),
679 times: 8,
680 }),
681 Effect.catchTag("NotFound", () => Effect.undefined),
682 );
683 if (operation !== undefined) {
684 yield* waitRegionOperation(env.project, region, operation).pipe(
685 Effect.catchTag("NotFound", () => Effect.void),
686 );
687 }
688 }),
689 });