summaryrefslogtreecommitdiff
path: root/server/health.ts
blob: e69077b68c5613064f2fe0879465093819f2309d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import {
  getRequiredEnv,
  getStdout,
  type HealthChecker,
  type HealthCheckInput,
  HealthCheckOutput,
  type IEither,
  type ITraceable,
  type ServerTrace,
  TraceUtil,
} from "@emprespresso/pengueno";

export const healthCheck: HealthChecker = (
  input: ITraceable<HealthCheckInput, ServerTrace>,
): Promise<IEither<Error, HealthCheckOutput>> =>
  input
    .bimap(TraceUtil.withFunctionTrace(healthCheck))
    .move(getRequiredEnv("LAMINAR_HOST"))
    // ensure LAMINAR_HOST is propagated to getStdout for other procedures
    .map((tEitherEnv) =>
      tEitherEnv
        .get()
        .flatMapAsync((_hasEnv) =>
          getStdout(tEitherEnv.move(["laminarc", "show-jobs"])),
        ),
    )
    .map(
      TraceUtil.promiseify((stdout) =>
        stdout.get().moveRight(HealthCheckOutput.YAASSSLAYQUEEN),
      ),
    )
    .get();