diff options
author | Elizabeth Alexander Hunt <me@liz.coffee> | 2025-05-15 23:39:29 -0700 |
---|---|---|
committer | Elizabeth Alexander Hunt <me@liz.coffee> | 2025-05-15 23:40:00 -0700 |
commit | 1ab20482ab37d7962c8e69701163270e687df3ca (patch) | |
tree | f0aaac54f8c23269fdeb2bca6f22e296a9e0559f /hooks/server | |
parent | 3a3fb9c8ab0c798a278f76d40de216fa96f6e2c4 (diff) | |
download | ci-1ab20482ab37d7962c8e69701163270e687df3ca.tar.gz ci-1ab20482ab37d7962c8e69701163270e687df3ca.zip |
more snapshot
Diffstat (limited to 'hooks/server')
-rw-r--r-- | hooks/server/mod.ts | 91 |
1 files changed, 54 insertions, 37 deletions
diff --git a/hooks/server/mod.ts b/hooks/server/mod.ts index c484af4..cc20827 100644 --- a/hooks/server/mod.ts +++ b/hooks/server/mod.ts @@ -1,39 +1,56 @@ -import { Either, type ITraceable } from "@emprespresso/pengueno"; +import { + getRequiredEnv, + getStdout, + type HealthCheckInput, + HealthCheckOutput, + type IEither, + type ITraceable, + TraceUtil, +} from "@emprespresso/pengueno"; +import {} from "../../u/trace/mod.ts"; -const healthCheck = async <Trace>(in: ITraceable<"healthy?", Trace>) => { - return getRequiredEnv("LAMINAR_HOST").flatMap((_host) => Either.fromFailableAsync( - getStdout(in.move(["laminarc", "show-jobs"])) - )) -} +const healthCheck = <Trace>( + input: ITraceable<HealthCheckInput, Trace>, +): Promise<IEither<Error, HealthCheckOutput>> => + 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 async route(req: ITraceable<req: Request, LogTraceable>) { - 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<Response> { - return LogTraceable(req).bimap(TraceUtil.withClassTrace(this)).map(this.route) - } -} -private route( - req: Traceable<Request & { pathname: string }>, -): Traceable<Promise<Response>> { - return req.flatMap((req) => { - const { logger, item: { method, pathname } } = req; - if (pathname === "/health") { - return this.healthCheckActivity.healthCheck(req); - } - return this.jobHookActivity.processHook(req); - }); -} +//export class LizCIServer { +// private constructor( +// private readonly healthCheckActivity = HealthCheckActivity(healthCheck), +// private readonly jobHookActivity = JobHookActivity(jobQueuer) +// ) {} +// +// private async route(req: ITraceable<req: Request, LogTraceable>) { +// 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<Response> { +// return LogTraceable(req).bimap(TraceUtil.withClassTrace(this)).map(this.route) +// } +//} +//private route( +// req: Traceable<Request & { pathname: string }>, +//): Traceable<Promise<Response>> { +// return req.flatMap((req) => { +// const { logger, item: { method, pathname } } = req; +// if (pathname === "/health") { +// return this.healthCheckActivity.healthCheck(req); +// } +// return this.jobHookActivity.processHook(req); +// }); +//} |