@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 67 lines 2.26 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import * as Kubernetes from "@alchemy.run/kubernetes";
3 import * as Effect from "effect/Effect";
4 import { EntriesTable, GuestbookCluster, GuestbookNamespace } from "./infra.ts";
5
6 const seedEntries = [
7 { id: "ada", message: "First computers, now clusters." },
8 {
9 id: "grace",
10 message: "A cluster in port is safe, but that is not what clusters are for.",
11 },
12 { id: "linus", message: "Talk is cheap. Show me the manifest." },
13 ];
14
15 /**
16 * A one-shot `Kubernetes.Job` in the INLINE EFFECT form: props + an init Effect
17 * whose impl returns `{ run }` — a one-shot entry that executes to
18 * completion inside the pod, after which the process exits (the Kubernetes
19 * analog of `AWS.ECS.Task`).
20 *
21 * The Effect program is bundled into a generated image
22 * (`main: import.meta.url` names this module as the entrypoint). The
23 * `AWS.DynamoDB.PutItem` binding injects the table's name into the pod and
24 * grants `dynamodb:PutItem` on the generated pod-identity role.
25 *
26 * Applying the batch/v1 Job runs it: the seed executes once on deploy.
27 * Adding `schedule: "0 3 * * *"` to the props would synthesize a CronJob
28 * instead.
29 */
30 export default Kubernetes.Job(
31 "SeedJob",
32 // Props are themselves an Effect so they can reference shared resources.
33 Effect.gen(function* () {
34 const cluster = yield* GuestbookCluster;
35 const ns = yield* GuestbookNamespace;
36 return {
37 cluster,
38 main: import.meta.url,
39 // Deploy after the namespace exists (see src/infra.ts).
40 namespace: ns.name,
41 backoffLimit: 2,
42 };
43 }),
44 Effect.gen(function* () {
45 const table = yield* EntriesTable;
46 const putItem = yield* AWS.DynamoDB.PutItem(table);
47
48 return {
49 // One-shot entry: seed the table, log, exit 0.
50 run: Effect.gen(function* () {
51 yield* Effect.forEach(
52 seedEntries,
53 (entry) =>
54 putItem({
55 Item: {
56 pk: { S: `entry#${entry.id}` },
57 author: { S: entry.id },
58 message: { S: entry.message },
59 },
60 }),
61 { discard: true },
62 );
63 yield* Effect.log(`seeded ${seedEntries.length} guestbook entries`);
64 }).pipe(Effect.orDie),
65 };
66 }).pipe(Effect.provide(AWS.DynamoDB.PutItemHttp)),
67 );