1import * as Kubernetes from "alchemy/Kubernetes";
2import * as Output from "alchemy/Output";
3import * as Effect from "effect/Effect";
4import * as Schedule from "effect/Schedule";
5import * as HttpClient from "effect/http/HttpClient";
6import * as HttpClientResponse from "effect/http/HttpClientResponse";
7import { Cluster, Namespace, Web } from "./infra.ts";
8
9export default Kubernetes.Job(
10 "SmokeTest",
11 Effect.gen(function* () {
12 const cluster = yield* Cluster;
13 const namespace = yield* Namespace;
14 return {
15 cluster,
16 main: import.meta.url,
17 name: "smoke-test",
18 namespace: namespace.name,
19 backoffLimit: 2,
20 ttlSecondsAfterFinished: 600,
21 };
22 }),
23 Effect.gen(function* () {
24 const web = yield* Web;
25 const webUrl =
26 yield* Output.interpolate`http://${web.serviceName}.${web.namespace}.svc.cluster.local:${web.port}`;
27
28 return {
29 run: Effect.gen(function* () {
30 const url = yield* webUrl;
31 const response = yield* HttpClient.get(`${url}/healthz`).pipe(
32 Effect.flatMap(HttpClientResponse.filterStatusOk),
33 Effect.retry({
34 schedule: Schedule.exponential("1 second"),
35 times: 5,
36 }),
37 );
38 yield* Effect.log(`${url} responded ${response.status}`);
39 }).pipe(Effect.orDie),
40 };
41 }),
42);