import { Either, type ITraceable } from "@emprespresso/pengueno"; const healthCheck = async (in: ITraceable<"healthy?", Trace>) => { return getRequiredEnv("LAMINAR_HOST").flatMap((_host) => Either.fromFailableAsync( getStdout(in.move(["laminarc", "show-jobs"])) )) } 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); }); }