1import * as Fly from "alchemy/Fly";
2import { ServerHost } from "alchemy/Server";
3import * as Effect from "effect/Effect";
4import * as FileSystem from "effect/FileSystem";
5import { MARKER, MARKER_FILE, Site, VOLUME_PATH } from "./shared.ts";
6
7/**
8 * Background Service: mounts a per-replica disk at `/data` and writes a
9 * marker file. No public proxy ports — {@link Api} is the HTTP surface.
10 */
11export default class Worker extends Fly.Service<Worker>()(
12 "Worker",
13 {
14 app: Site,
15 main: import.meta.url,
16 region: "iad",
17 guest: { cpuKind: "shared", cpus: 1, memoryMb: 256 },
18 services: [],
19 },
20 Effect.gen(function* () {
21 const mount = yield* Fly.MountVolume({ path: VOLUME_PATH, sizeGb: 1 });
22 const host = yield* ServerHost;
23 const fs = yield* FileSystem.FileSystem;
24
25 yield* host.run(
26 Effect.gen(function* () {
27 yield* fs.makeDirectory(mount.path, { recursive: true });
28 yield* fs.writeFileString(MARKER_FILE, MARKER);
29 return yield* Effect.never;
30 }).pipe(Effect.orDie),
31 );
32 }).pipe(Effect.provide(Fly.MountVolumeLive)),
33) {}