summaryrefslogtreecommitdiff
path: root/hooks/server/mod.ts
diff options
context:
space:
mode:
Diffstat (limited to 'hooks/server/mod.ts')
-rw-r--r--hooks/server/mod.ts39
1 files changed, 39 insertions, 0 deletions
diff --git a/hooks/server/mod.ts b/hooks/server/mod.ts
index e69de29..c484af4 100644
--- a/hooks/server/mod.ts
+++ b/hooks/server/mod.ts
@@ -0,0 +1,39 @@
+import { Either, type ITraceable } from "@emprespresso/pengueno";
+
+const healthCheck = async <Trace>(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<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);
+ });
+}