@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 47 lines 1.88 KB
Raw
1 import * as Cloudflare from "@alchemy.run/cloudflare";
2 import * as Effect from "effect/Effect";
3 import * as Schedule from "effect/Schedule";
4 import { EffectfulContainer } from "./effectful-container.ts";
5
6 /**
7 * Durable Object backing one effectful container instance. `boot()` blocks
8 * until the container is accepting RPC (`ping()` answers). NOTE: the
9 * authoritative cold-start clock runs in the Worker AROUND the whole DO call,
10 * so it also covers Durable Object construction.
11 *
12 * Each distinct `getByName(name)` is a distinct DO instance and therefore a
13 * distinct container instance, which is how the benchmark spins up N of them.
14 */
15 export class EffectfulObject extends Cloudflare.DurableObject<EffectfulObject>()(
16 "BenchEffectfulObject",
17 Effect.gen(function* () {
18 const container = yield* EffectfulContainer;
19
20 return Effect.gen(function* () {
21 return {
22 // Time container cold-start → reachable (RPC answers). Leaves the
23 // container running so the benchmark can `shutdown()` it separately —
24 // the timing must not include teardown. A freshly-built image is still
25 // distributing to the edge metal on the first boots, so retry until the
26 // RPC port answers.
27 boot: () =>
28 Effect.gen(function* () {
29 const start = yield* Effect.sync(() => Date.now());
30 yield* container.start({ enableInternet: true });
31 yield* container.ping().pipe(
32 Effect.retry({
33 schedule: Schedule.min([
34 Schedule.exponential("1 second"),
35 Schedule.spaced("5 seconds"),
36 ]),
37 times: 40,
38 }),
39 );
40 const readyMs = (yield* Effect.sync(() => Date.now())) - start;
41 return { readyMs };
42 }),
43 shutdown: () => container.destroy().pipe(Effect.ignore),
44 };
45 });
46 }),
47 ) {}