From 9cf3fc0259730b7dcf47b3ab4a04369e39fb4614 Mon Sep 17 00:00:00 2001 From: Elizabeth Alexander Hunt Date: Sun, 18 May 2025 12:24:09 -0700 Subject: finish up pengueno --- u/server/activity/fourohfour.ts | 23 +++++++++------------ u/server/activity/health.ts | 45 ++++++++++++++++++++++++----------------- u/server/activity/mod.ts | 4 ++-- 3 files changed, 38 insertions(+), 34 deletions(-) (limited to 'u/server/activity') diff --git a/u/server/activity/fourohfour.ts b/u/server/activity/fourohfour.ts index 698dacd..48740df 100644 --- a/u/server/activity/fourohfour.ts +++ b/u/server/activity/fourohfour.ts @@ -1,16 +1,10 @@ import { type ITraceable, JsonResponse, - TraceUtil, + type PenguenoRequest, + type ServerTrace, } from "@emprespresso/pengueno"; -export enum HealthCheckInput { - CHECK, -} -export enum HealthCheckOutput { - YAASQUEEN, -} - const messages = [ "(≧ω≦)ゞ Oopsie! This endpoint has gone a-404-dable!", "。゚(。ノωヽ。)゚。 Meow-t found! Your API call ran away!", @@ -21,10 +15,13 @@ const messages = [ "(ꈍᴗꈍ) Uwu~ not found, but found our hearts instead!", "ヽ(;▽;)ノ Eep! This route has ghosted you~", ]; -export const FourOhFourActivity = (req: ITraceable) => - req.bimap(TraceUtil.withFunctionTrace(FourOhFourActivity)) - .map(() => - new JsonResponse(messages[Math.random() * messages.length], { +const randomFourOhFour = () => messages[Math.random() * messages.length]; +export const FourOhFourActivity = ( + req: ITraceable, +) => + req + .move( + new JsonResponse(req, randomFourOhFour(), { status: 404, - }) + }), ); 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 = ( +const healthCheckMetric = Metric.fromName("Health"); +export const HealthCheckActivity = ( check: Mapper< - ITraceable, + ITraceable, Promise> >, ) => -(req: ITraceable) => - req.bimap(TraceUtil.withFunctionTrace(HealthCheckActivity)) - .flatMap((r) => r.move(HealthCheckInput.CHECK)) - .map(check) - .map(TraceUtil.promiseify(({ item: health, trace }) => { +(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) => { - 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 }, ); }); })); diff --git a/u/server/activity/mod.ts b/u/server/activity/mod.ts index f0cbed2..9bd512f 100644 --- a/u/server/activity/mod.ts +++ b/u/server/activity/mod.ts @@ -1,4 +1,4 @@ -import { JsonResponse, type RequestFilter } from "@emprespresso/pengueno"; +import type { PenguenoResponse, RequestFilter } from "@emprespresso/pengueno"; export enum StatusOK { FOLLOW = 300, @@ -9,7 +9,7 @@ export interface ActivityOk { } export interface IActivity - extends RequestFilter { + extends RequestFilter { } export * from "./health.ts"; -- cgit v1.2.3-70-g09d2