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

main
ts 35 lines 1.16 KB
Raw
1 import { Query } from "@distilled.cloud/core/query";
2 import { Railway } from "@distilled.cloud/railway";
3 import * as Effect from "effect/Effect";
4 import * as Schedule from "effect/Schedule";
5
6 const isGoneInstance = (instance: {
7 deletedAt: string | null;
8 isPendingDeletion: boolean;
9 state: string | null;
10 }) =>
11 instance.deletedAt != null ||
12 instance.isPendingDeletion ||
13 instance.state === "DELETED" ||
14 instance.state === "DELETING";
15
16 const readVolumeInstance = Query.fn((id: string) => {
17 const instance = Railway.volumeInstance({ id });
18 return {
19 deletedAt: instance.deletedAt,
20 isPendingDeletion: instance.isPendingDeletion,
21 state: instance.state,
22 };
23 });
24
25 /** Poll `volumeInstance({id})` until Railway reports the instance gone. */
26 export const waitUntilVolumeGone = (volumeInstanceId: string) =>
27 readVolumeInstance(volumeInstanceId).pipe(
28 Effect.map((instance) => (isGoneInstance(instance) ? ("gone" as const) : ("found" as const))),
29 Effect.catchTag("RailwayNotFound", () => Effect.succeed("gone" as const)),
30 Effect.repeat({
31 schedule: Schedule.spaced("1 second"),
32 until: (status) => status === "gone",
33 times: 10,
34 }),
35 );