t3-code-android-nightly/.repos/alchemy-effect/packages/alchemy/test/Fly/fixtures/flycast.ts
Julius Marminge 6f9cea00ae
chore(refs): sync Effect and Alchemy references to 4.0.1 and beta.80 (#16170)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 13:22:30 -07:00

54 lines
1.5 KiB
TypeScript

import * as machines from "@distilled.cloud/fly-io/machines";
import * as Effect from "effect/Effect";
import * as Schedule from "effect/Schedule";
export const nginx = {
region: "iad",
image: "nginx:alpine",
guest: { cpus: 1, memoryMb: 256 },
};
/** Plain HTTP on port 80: Fly issues no TLS certificate for `.flycast`. */
export const httpService = {
protocol: "tcp",
internalPort: 80,
ports: [{ port: 80, handlers: ["http"] }],
autostart: true,
autostop: "off" as const,
};
/** Fetch `url` from inside a Machine until the body contains `expected`. */
export const fetchFrom = (
caller: { appName: string; machineId: string },
url: string,
expected = "Welcome to nginx",
) =>
machines
.execMachine({
app_name: caller.appName,
machine_id: caller.machineId,
command: ["sh", "-c", `wget -qO- -T 5 ${url} || true`],
timeout: 15,
})
.pipe(
Effect.repeat({
schedule: Schedule.spaced("3 seconds"),
times: 20,
until: (result) => result.stdout?.includes(expected) === true,
}),
Effect.map((result) => result.stdout ?? ""),
);
/** Fetch `url` once from inside a Machine; returns the body or wget's error. */
export const fetchOnce = (
caller: { appName: string; machineId: string },
url: string,
) =>
machines
.execMachine({
app_name: caller.appName,
machine_id: caller.machineId,
command: ["sh", "-c", `wget -qO- -T 5 ${url} 2>&1 || true`],
timeout: 15,
})
.pipe(Effect.map((result) => result.stdout ?? ""));