From ef51b25e4388cbdf3a27e23d9f1fa381ae20a5ad Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Fri, 16 May 2025 16:17:13 -0700 Subject: snapshot --- hooks/server/health.ts | 23 ++++++++++++++++ hooks/server/mod.ts | 71 ++++++++++++++++++-------------------------------- 2 files changed, 49 insertions(+), 45 deletions(-) create mode 100644 hooks/server/health.ts (limited to 'hooks/server') diff --git a/hooks/server/health.ts b/hooks/server/health.ts new file mode 100644 index 0000000..41dfcb4 --- /dev/null +++ b/hooks/server/health.ts @@ -0,0 +1,23 @@ +import { + getRequiredEnv, + getStdout, + type HealthCheckInput, + HealthCheckOutput, + type IEither, + type ITraceable, + TraceUtil, +} from "@emprespresso/pengueno"; + +export const healthCheck = ( + input: ITraceable, +): Promise> => + 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; diff --git a/hooks/server/mod.ts b/hooks/server/mod.ts index cc20827..b635b05 100644 --- a/hooks/server/mod.ts +++ b/hooks/server/mod.ts @@ -5,52 +5,33 @@ import { HealthCheckOutput, type IEither, type ITraceable, + LogTraceable, TraceUtil, } from "@emprespresso/pengueno"; -import {} from "../../u/trace/mod.ts"; -const healthCheck = ( - input: ITraceable, -): Promise> => - 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; +export class LizCIServer { + private constructor( + private readonly healthCheckActivity = HealthCheckActivity(healthCheck), + private readonly jobHookActivity = JobHookActivity(jobQueuer), + private readonly fourOhFourActivity = FourOhFourActivity(), + ) {} -//export class LizCIServer { -// private constructor( -// private readonly healthCheckActivity = HealthCheckActivity(healthCheck), -// private readonly jobHookActivity = JobHookActivity(jobQueuer) -// ) {} -// -// private async route(req: ITraceable) { -// return req.flatMap((req) => { -// const { logger, item: { method, pathname } } = req; -// if (pathname === "/health") { -// return this.healthCheckActivity.healthCheck(req); -// } -// return this.jobHookActivity.processHook(req); -// }); -// } -// -// public async serve(req: Request): Promise { -// return LogTraceable(req).bimap(TraceUtil.withClassTrace(this)).map(this.route) -// } -//} -//private route( -// req: Traceable, -//): Traceable> { -// return req.flatMap((req) => { -// const { logger, item: { method, pathname } } = req; -// if (pathname === "/health") { -// return this.healthCheckActivity.healthCheck(req); -// } -// return this.jobHookActivity.processHook(req); -// }); -//} + private async route(req: LogTraceable) { + return req.flatMap((req) => { + const { item: request } = req; + const url = new URL(request.url); + if (url.pathname === "/health") { + return this.healthCheckActivity.healthCheck(req); + } + if (url.pathname === "/job") { + return this.jobHookActivity.processHook(req); + } + }); + } + + public async serve(req: Request): Promise { + return LogTraceable(req).bimap(TraceUtil.withClassTrace(this)).map( + this.route, + ); + } +} -- cgit v1.2.3-70-g09d2