import { type IEither, type ITraceable, JsonResponse, LogLevel, type Mapper, Metric, type PenguenoRequest, type ServerTrace, TraceUtil, } from "@emprespresso/pengueno"; export enum HealthCheckInput { CHECK, } export enum HealthCheckOutput { YAASQUEEN, } const healthCheckMetric = Metric.fromName("Health"); export const HealthCheckActivity = ( check: Mapper< ITraceable, Promise> >, ) => (req: ITraceable) => req .bimap(TraceUtil.withFunctionTrace(HealthCheckActivity)) .bimap(TraceUtil.withMetricTrace(healthCheckMetric)) .flatMap((r) => r.move(HealthCheckInput.CHECK).map(check)) .map(TraceUtil.promiseify((h) => { const health = h.get(); health.mapBoth((e) => { h.trace.trace(healthCheckMetric.failure); h.trace.addTrace(LogLevel.ERROR).trace(`${e}`); return new JsonResponse( req, "oh no, i need to eat more vegetables (。•́︿•̀。)...", { status: 500 }, ); }, (_healthy) => { h.trace.trace(healthCheckMetric.success); const msg = `think im healthy!! (✿˘◡˘) ready to do work~`; h.trace.trace(msg); return new JsonResponse( req, msg, { status: 200 }, ); }); }));