summaryrefslogtreecommitdiff
path: root/hooks/server/health.ts
blob: 41dfcb46781453f161930a0fb3cba559daefdc04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import {
  getRequiredEnv,
  getStdout,
  type HealthCheckInput,
  HealthCheckOutput,
  type IEither,
  type ITraceable,
  TraceUtil,
} from "@emprespresso/pengueno";

export const healthCheck = <Trace>(
  input: ITraceable<HealthCheckInput, Trace>,
): Promise<IEither<Error, HealthCheckOutput>> =>
  input.bimap(TraceUtil.withFunctionTrace(healthCheck))
    .move(getRequiredEnv("LAMINAR_HOST"))
    // we need to test LAMINAR_HOST is propagated to getStdout for other procedures
    .map(({ item }) => item.moveRight(["laminarc", "show-jobs"]))
    .map((i) =>
      i.item.mapRight(i.move.apply)
        .flatMapAsync(getStdout.apply)
        .then((gotJobs) => gotJobs.moveRight(HealthCheckOutput.YAASQUEEN))
    )
    .item;