summaryrefslogtreecommitdiff
path: root/u/server/activity/health.ts
diff options
context:
space:
mode:
Diffstat (limited to 'u/server/activity/health.ts')
-rw-r--r--u/server/activity/health.ts45
1 files changed, 26 insertions, 19 deletions
diff --git a/u/server/activity/health.ts b/u/server/activity/health.ts
index 98acbb8..b9efa3a 100644
--- a/u/server/activity/health.ts
+++ b/u/server/activity/health.ts
@@ -1,8 +1,12 @@
import {
type IEither,
type ITraceable,
+ JsonResponse,
LogLevel,
type Mapper,
+ Metric,
+ type PenguenoRequest,
+ type ServerTrace,
TraceUtil,
} from "@emprespresso/pengueno";
@@ -13,33 +17,36 @@ export enum HealthCheckOutput {
YAASQUEEN,
}
-export const HealthCheckActivity = <Trace>(
+const healthCheckMetric = Metric.fromName("Health");
+export const HealthCheckActivity = (
check: Mapper<
- ITraceable<HealthCheckInput, Trace>,
+ ITraceable<HealthCheckInput, ServerTrace>,
Promise<IEither<Error, HealthCheckOutput>>
>,
) =>
-(req: ITraceable<Request, Trace>) =>
- req.bimap(TraceUtil.withFunctionTrace(HealthCheckActivity))
- .flatMap((r) => r.move(HealthCheckInput.CHECK))
- .map(check)
- .map(TraceUtil.promiseify(({ item: health, trace }) => {
+(req: ITraceable<PenguenoRequest, ServerTrace>) =>
+ 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) => {
- trace.addTrace(LogLevel.ERROR).trace(`${e}`);
- return new Response(
- JSON.stringify({
- message: "oh no, i need to eat more vegetables (。•́︿•̀。)...",
- }),
- { status: 500, headers: { "Content-Type": "application/json" } },
+ 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~`;
- trace.trace(msg);
- return new Response(
- JSON.stringify({
- message: "oh no, i need to eat more vegetables (。•́︿•̀。)...",
- }),
- { status: 500, headers: { "Content-Type": "application/json" } },
+ h.trace.trace(msg);
+ return new JsonResponse(
+ req,
+ msg,
+ { status: 200 },
);
});
}));