@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, 07:15 UTC

main
ts 41 lines 1.72 KB
Raw
1 import * as Cloudflare from "@alchemy.run/cloudflare";
2 import * as Effect from "effect/Effect";
3 import * as HttpClientRequest from "effect/http/HttpClientRequest";
4 import { RestartContainer } from "./container.ts";
5
6 /**
7 * Durable Object backing one {@link RestartContainer} instance, exposing the
8 * levers the restart tests need:
9 * - `ping` — start the container (if stopped) and RPC into it
10 * - `running` — the raw `container.running` flag
11 * - `stop` — hard stop from the DO side (`destroy` = SIGKILL)
12 * - `crash` — make the container process exit on its own (non-zero)
13 */
14 export class RestartObject extends Cloudflare.DurableObject<RestartObject>()(
15 "RestartObject",
16 Effect.gen(function* () {
17 const container = yield* RestartContainer;
18
19 return Effect.gen(function* () {
20 // Starting is idempotent: calling it before every request restarts a
21 // container that was stopped or crashed since the last one.
22 const start = container.start({ enableInternet: true });
23 return {
24 ping: () => start.pipe(Effect.andThen(container.ping())),
25 running: () => container.running,
26 // Hard stop from the DO side. Exercises the "container stopped, then
27 // started again by the next request" path.
28 stop: () => container.destroy(),
29 // Crash from inside the container process. Exercises the
30 // monitor-observed-exit restart path.
31 crash: () =>
32 Effect.gen(function* () {
33 yield* start;
34 const { fetch } = yield* container.getTcpPort(3000);
35 const response = yield* fetch(HttpClientRequest.get("http://container/exit"));
36 return yield* response.text;
37 }).pipe(Effect.orDie),
38 };
39 });
40 }),
41 ) {}