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

main
ts 28 lines 1.03 KB
Raw
1 import type { DockerImagePublicationError } from "@alchemy.run/docker/RegistryError";
2 import type { TimeoutError } from "effect/Cause";
3 import * as Effect from "effect/Effect";
4 import * as Schedule from "effect/Schedule";
5
6 export const retryContainerPublication = <
7 A,
8 E extends DockerImagePublicationError | TimeoutError,
9 R,
10 >(
11 publication: Effect.Effect<A, E, R>,
12 ) =>
13 Effect.retry(publication, {
14 while: (error) =>
15 error._tag === "DockerRegistryBlobUnknown" ||
16 error._tag === "DockerRegistryUnavailable" ||
17 error._tag === "TimeoutError",
18 schedule: Schedule.max([Schedule.spaced("3 seconds"), Schedule.recurs(5)]),
19 });
20
21 /**
22 * Publishes an image build with a deadline per attempt. A stalled BuildKit
23 * export never fails on its own, so each attempt times out after three
24 * minutes and is retried alongside transient registry errors.
25 */
26 export const retryContainerBuild = <A, R>(
27 build: Effect.Effect<A, DockerImagePublicationError, R>,
28 ) => build.pipe(Effect.timeout("3 minutes"), retryContainerPublication);