@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 80 lines 3.5 KB
Raw
1 import { Region as AwsRegion } from "@distilled.cloud/aws/Region";
2 import * as Effect from "effect/Effect";
3 import * as Schedule from "effect/Schedule";
4
5 // Global Accelerator is a global service, but its control-plane API only
6 // exists in us-west-2 ("you must specify the US West (Oregon) Region to
7 // create, update, or otherwise work with accelerators"). Pin every call so
8 // the resources work regardless of the ambient deployment region.
9 export const GA_REGION = "us-west-2" as const;
10
11 // NOTE: the Region service's value is an Effect<RegionName>, not a string.
12 export const withGaRegion = <A, E, R>(effect: Effect.Effect<A, E, R>) =>
13 effect.pipe(Effect.provideService(AwsRegion, Effect.succeed(GA_REGION)));
14
15 /**
16 * Global Accelerator serializes configuration changes per accelerator as
17 * "transactions"; a second mutation while one is propagating is rejected with
18 * `TransactionInProgressException` (or `ConflictException`). Retry on a
19 * bounded schedule (~60s) until the in-flight transaction lands.
20 *
21 * NOTE: explicit return annotation is load-bearing — an inline `Effect.retry`
22 * in provider lifecycle code leaks `Retry.Return` conditionals into
23 * declaration emit and widens the provider layer to `unknown` R.
24 */
25 export const retryGaTransaction = <A, E extends { _tag: string }, R>(
26 self: Effect.Effect<A, E, R>,
27 ): Effect.Effect<A, E, R> =>
28 Effect.retry(self, {
29 while: (e) => e._tag === "TransactionInProgressException" || e._tag === "ConflictException",
30 schedule: Schedule.max([Schedule.fixed("3 seconds"), Schedule.recurs(20)]),
31 });
32
33 /**
34 * Deletion is subject to both GA's serialized transactions and occasional
35 * transient internal-service failures. Keep the retry bounded to about one
36 * minute so teardown converges without hanging indefinitely.
37 */
38 export const retryGaDeletion = <A, E extends { _tag: string }, R>(
39 self: Effect.Effect<A, E, R>,
40 ): Effect.Effect<A, E, R> =>
41 Effect.retry(self, {
42 while: (e) =>
43 e._tag === "TransactionInProgressException" ||
44 e._tag === "ConflictException" ||
45 e._tag === "InternalServiceErrorException",
46 schedule: Schedule.max([Schedule.fixed("3 seconds"), Schedule.recurs(20)]),
47 });
48
49 /**
50 * `deleteAccelerator` requires the accelerator to be fully disabled and all
51 * listeners removed. Both conditions clear asynchronously after the disabling
52 * `updateAccelerator` / dependent deletes return, so retry the delete on a
53 * bounded schedule (~3 minutes) until the disable transaction propagates.
54 */
55 export const retryUntilAcceleratorDeletable = <A, E extends { _tag: string }, R>(
56 self: Effect.Effect<A, E, R>,
57 ): Effect.Effect<A, E, R> =>
58 Effect.retry(self, {
59 while: (e) =>
60 e._tag === "AcceleratorNotDisabledException" ||
61 e._tag === "AssociatedListenerFoundException" ||
62 e._tag === "TransactionInProgressException" ||
63 e._tag === "InternalServiceErrorException",
64 schedule: Schedule.max([Schedule.fixed("5 seconds"), Schedule.recurs(36)]),
65 });
66
67 /**
68 * `deleteListener` is rejected with `AssociatedEndpointGroupFoundException`
69 * while a just-deleted endpoint group is still detaching. Retry briefly.
70 */
71 export const retryUntilListenerDeletable = <A, E extends { _tag: string }, R>(
72 self: Effect.Effect<A, E, R>,
73 ): Effect.Effect<A, E, R> =>
74 Effect.retry(self, {
75 while: (e) =>
76 e._tag === "AssociatedEndpointGroupFoundException" ||
77 e._tag === "TransactionInProgressException" ||
78 e._tag === "InternalServiceErrorException",
79 schedule: Schedule.max([Schedule.fixed("5 seconds"), Schedule.recurs(24)]),
80 });