summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElizabeth Alexander Hunt <me@liz.coffee>2025-05-15 23:39:29 -0700
committerElizabeth Alexander Hunt <me@liz.coffee>2025-05-15 23:40:00 -0700
commit1ab20482ab37d7962c8e69701163270e687df3ca (patch)
treef0aaac54f8c23269fdeb2bca6f22e296a9e0559f
parent3a3fb9c8ab0c798a278f76d40de216fa96f6e2c4 (diff)
downloadci-1ab20482ab37d7962c8e69701163270e687df3ca.tar.gz
ci-1ab20482ab37d7962c8e69701163270e687df3ca.zip
more snapshot
-rw-r--r--deno.json2
-rw-r--r--hooks/server/mod.ts91
-rw-r--r--u/fn/either.ts31
-rw-r--r--u/process/run.ts4
-rw-r--r--u/server/activity/health.ts18
-rw-r--r--u/server/activity/mod.ts2
-rw-r--r--u/server/filter/json.ts3
-rw-r--r--u/server/filter/method.ts3
-rw-r--r--u/server/mod.ts1
-rwxr-xr-xworker/scripts/fetch_code4
10 files changed, 101 insertions, 58 deletions
diff --git a/deno.json b/deno.json
index 7c696db..6b5c03d 100644
--- a/deno.json
+++ b/deno.json
@@ -1,3 +1,3 @@
{
- "workspace": ["./model", "./worker", "./hooks", "./utils", "./lizutils"]
+ "workspace": ["./model", "./worker", "./hooks", "./utils", "./u"]
}
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);
+// });
+//}
diff --git a/u/fn/either.ts b/u/fn/either.ts
index 12240d0..916bb71 100644
--- a/u/fn/either.ts
+++ b/u/fn/either.ts
@@ -5,37 +5,56 @@ export interface IEither<E, T> {
errBranch: Mapper<E, Ee>,
okBranch: Mapper<T, Tt>,
) => IEither<Ee, Tt>;
- flatMap: <Tt>(mapper: Mapper<T, IEither<E, Tt>>) => IEither<E, Tt>;
+ moveRight: <Tt>(t: Tt) => IEither<E, Tt>;
mapRight: <Tt>(mapper: Mapper<T, Tt>) => IEither<E, Tt>;
mapLeft: <Ee>(mapper: Mapper<E, Ee>) => IEither<Ee, T>;
+ flatMap: <Tt>(mapper: Mapper<T, IEither<E, Tt>>) => IEither<E, Tt>;
+ flatMapAsync: <Tt>(
+ mapper: Mapper<T, Promise<IEither<E, Tt>>>,
+ ) => Promise<IEither<E, Tt>>;
}
export class Either<E, T> implements IEither<E, T> {
private constructor(private readonly err?: E, private readonly ok?: T) {}
+ public moveRight<Tt>(
+ t: Tt,
+ ) {
+ return this.mapRight(() => t);
+ }
+
public mapBoth<Ee, Tt>(
errBranch: Mapper<E, Ee>,
okBranch: Mapper<T, Tt>,
): Either<Ee, Tt> {
- if (this.err) return Either.left(errBranch(this.err));
+ if (this.err !== undefined) return Either.left(errBranch(this.err));
return Either.right(okBranch(this.ok!));
}
public flatMap<Tt>(mapper: Mapper<T, Either<E, Tt>>): Either<E, Tt> {
- if (this.ok) return mapper(this.ok);
+ if (this.ok !== undefined) return mapper(this.ok);
return Either.left<E, Tt>(this.err!);
}
public mapRight<Tt>(mapper: Mapper<T, Tt>): IEither<E, Tt> {
- if (this.ok) return Either.right(mapper(this.ok));
+ if (this.ok !== undefined) return Either.right(mapper(this.ok));
return Either.left<E, Tt>(this.err!);
}
- public mapLeft<Ee>(mapper: Mapper<E, Ee>) {
- if (this.err) return Either.left<Ee, T>(mapper(this.err));
+ public mapLeft<Ee>(mapper: Mapper<E, Ee>): IEither<Ee, T> {
+ if (this.err !== undefined) return Either.left<Ee, T>(mapper(this.err));
return Either.right<Ee, T>(this.ok!);
}
+ public async flatMapAsync<Tt>(
+ mapper: Mapper<T, Promise<IEither<E, Tt>>>,
+ ): Promise<IEither<E, Tt>> {
+ if (this.err !== undefined) {
+ return Promise.resolve(Either.left<E, Tt>(this.err));
+ }
+ return await mapper(this.ok!).catch((err) => Either.left<E, Tt>(err as E));
+ }
+
static left<E, T>(e: E) {
return new Either<E, T>(e);
}
diff --git a/u/process/run.ts b/u/process/run.ts
index 670f567..cbf8c65 100644
--- a/u/process/run.ts
+++ b/u/process/run.ts
@@ -14,8 +14,8 @@ type CommandOutputDecoded = {
};
export class ProcessError extends Error {}
-export const getStdout = (
- c: ITraceable<Command>,
+export const getStdout = <Trace>(
+ c: ITraceable<Command, Trace>,
options: Deno.CommandOptions = {},
): Promise<IEither<ProcessError, string>> =>
c.bimap(TraceUtil.withFunctionTrace(getStdout))
diff --git a/u/server/activity/health.ts b/u/server/activity/health.ts
index bf1f52c..7ee6629 100644
--- a/u/server/activity/health.ts
+++ b/u/server/activity/health.ts
@@ -1,25 +1,27 @@
import {
- Either,
- getRequiredEnv,
- getStdout,
+ type IEither,
type ITraceable,
LogLevel,
type Mapper,
TraceUtil,
} from "@emprespresso/pengueno";
-type HealthCheckInput = "healthy?";
-type HealthCheckOutput = "healthy!";
+export enum HealthCheckInput {
+ CHECK,
+}
+export enum HealthCheckOutput {
+ YAASQUEEN,
+}
-const HealthCheckActivity = <Trace>(
+export const HealthCheckActivity = <Trace>(
check: Mapper<
ITraceable<HealthCheckInput, Trace>,
- Promise<Either<Error, HealthCheckOutput>>
+ Promise<IEither<Error, HealthCheckOutput>>
>,
) =>
(req: ITraceable<Request, Trace>) =>
req.bimap(TraceUtil.withFunctionTrace(HealthCheckActivity))
- .flatMap((r) => r.move(<HealthCheckInput> "healthy?"))
+ .flatMap((r) => r.move(HealthCheckInput.CHECK))
.map(check)
.map(TraceUtil.promiseify(({ item: health, trace }) => {
health.mapBoth((e) => {
diff --git a/u/server/activity/mod.ts b/u/server/activity/mod.ts
index 6908c26..9d05d3c 100644
--- a/u/server/activity/mod.ts
+++ b/u/server/activity/mod.ts
@@ -6,3 +6,5 @@ export class r200 extends Response {
export interface IActivity<Trace> extends RequestFilter<r200, Trace> {
}
+
+export * from "./health.ts";
diff --git a/u/server/filter/json.ts b/u/server/filter/json.ts
index 3f11915..f8e4607 100644
--- a/u/server/filter/json.ts
+++ b/u/server/filter/json.ts
@@ -29,4 +29,5 @@ export const json = <BodyT, Trace, JsonT = unknown>(
return new Response(err.message, { status: 400 });
})
),
- ).item;
+ )
+ .item;
diff --git a/u/server/filter/method.ts b/u/server/filter/method.ts
index 2bf45a0..a1401b4 100644
--- a/u/server/filter/method.ts
+++ b/u/server/filter/method.ts
@@ -34,4 +34,5 @@ export const requireMethod =
}
return Either.right<Response, HttpMethod>(method);
- })).item;
+ }))
+ .item;
diff --git a/u/server/mod.ts b/u/server/mod.ts
index 556771d..52b26e2 100644
--- a/u/server/mod.ts
+++ b/u/server/mod.ts
@@ -1 +1,2 @@
export * from "./filter/mod.ts";
+export * from "./activity/mod.ts";
diff --git a/worker/scripts/fetch_code b/worker/scripts/fetch_code
index 83a5612..4dfb7ab 100755
--- a/worker/scripts/fetch_code
+++ b/worker/scripts/fetch_code
@@ -5,7 +5,7 @@ export LOG_PREFIX="[fetch_code $remote @ $checkout -> $path]"
log "getting the codez~ time to fetch!"
git clone "$remote" "$path"
if [ ! $? -eq 0 ]; then
- log "oh nyo! couldn't clone the repo"
+ log "D: oh nyo! couldn't clone the repo"
exit 1
fi
@@ -13,7 +13,7 @@ cd "$path"
log "switching to $checkout like a good kitty~"
git reset --hard "$checkout"
if [ ! $? -eq 0 ]; then
- log "ouchie! can't reset to $checkout"
+ log "D: can't reset to $checkout"
cd -
exit 1
fi