summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xmod.ts2
-rw-r--r--server/health.ts13
-rw-r--r--u/fn/either.ts14
-rw-r--r--u/process/env.ts7
-rw-r--r--u/server/activity/health.ts12
-rw-r--r--u/trace/itrace.ts4
-rw-r--r--worker/Dockerfile8
7 files changed, 29 insertions, 31 deletions
diff --git a/mod.ts b/mod.ts
index 0af8943..98470fc 100755
--- a/mod.ts
+++ b/mod.ts
@@ -29,7 +29,7 @@ if (import.meta.main) {
eitherDone.fold(({ isLeft, value }) => {
if (!isLeft) return;
- console.error(value);
+ console.error(`Failed to start`, value);
Deno.exit(1);
}),
);
diff --git a/server/health.ts b/server/health.ts
index 1acc074..8fbc69d 100644
--- a/server/health.ts
+++ b/server/health.ts
@@ -17,12 +17,9 @@ export const healthCheck: HealthChecker = (
.bimap(TraceUtil.withFunctionTrace(healthCheck))
.move(getRequiredEnv("LAMINAR_HOST"))
// ensure LAMINAR_HOST is propagated to getStdout for other procedures
- .map((e) => e.get().moveRight(["laminarc", "show-jobs"]))
- .map((i) =>
- i
- .get()
- .mapRight(i.move.apply)
- .flatMapAsync(getStdout.apply)
- .then((gotJobs) => gotJobs.moveRight(HealthCheckOutput.YAASSSLAYQUEEN)),
- )
+ .map((tEitherEnv) => tEitherEnv.get()
+ .flatMapAsync((_hasEnv) =>
+ getStdout(tEitherEnv.move(["laminarc", "show-jobs"]))
+ ))
+ .map(TraceUtil.promiseify((stdout) => stdout.get().moveRight(HealthCheckOutput.YAASSSLAYQUEEN)))
.get();
diff --git a/u/fn/either.ts b/u/fn/either.ts
index bf90f16..54f9fc2 100644
--- a/u/fn/either.ts
+++ b/u/fn/either.ts
@@ -32,14 +32,13 @@ export class Either<E, T> implements IEither<E, T> {
private readonly self: Left<E> | Right<T>;
private constructor(
- err?: E,
- ok?: T,
+ init: { err?: E, ok?: T },
public readonly _tag: IEitherTag = iEitherTag,
) {
this.self = <Left<E> | Right<T>>{
- isLeft: typeof err !== "undefined",
- isRight: typeof ok !== "undefined",
- value: typeof err !== "undefined" ? err : ok!,
+ isLeft: "err" in init,
+ isRight: "ok" in init,
+ value: init.err ?? init.ok!,
};
}
@@ -86,10 +85,11 @@ export class Either<E, T> implements IEither<E, T> {
}
static left<E, T>(e: E): IEither<E, T> {
- return new Either<E, T>(e, undefined);
+ return new Either<E, T>({ err: e});
}
+
static right<E, T>(t: T): IEither<E, T> {
- return new Either<E, T>(undefined, t);
+ return new Either<E, T>({ok: t});
}
static fromFailable<E, T>(s: Supplier<T>): IEither<E, T> {
diff --git a/u/process/env.ts b/u/process/env.ts
index c0d893c..470cb39 100644
--- a/u/process/env.ts
+++ b/u/process/env.ts
@@ -1,11 +1,10 @@
import { Either, type IEither } from "@emprespresso/pengueno";
export const getRequiredEnv = <V extends string>(name: V): IEither<Error, V> =>
- Either.fromFailable<Error, V>(() => Deno.env.get(name) as V) // could throw when no permission.
+ Either.fromFailable<Error, V | undefined>(() => Deno.env.get(name) as V | undefined) // could throw when no permission.
.flatMap(
- (v) =>
- (v && Either.right(v)) ||
- Either.left(new Error(`environment variable "${name}" is required D:`)),
+ (v) => (v && Either.right(v)) ||
+ Either.left(new Error(`environment variable "${name}" is required D:`))
);
type ObjectFromList<T extends ReadonlyArray<string>, V = string> = {
diff --git a/u/server/activity/health.ts b/u/server/activity/health.ts
index b9dedf9..3b4a23a 100644
--- a/u/server/activity/health.ts
+++ b/u/server/activity/health.ts
@@ -35,16 +35,18 @@ export class HealthCheckActivityImpl implements IHealthCheckActivity {
return req
.bimap(TraceUtil.withFunctionTrace(this.checkHealth))
.bimap(TraceUtil.withMetricTrace(healthCheckMetric))
- .flatMap((r) => r.move(HealthCheckInput.CHECK).map(this.check))
+ .flatMap((r) =>
+ r.move(HealthCheckInput.CHECK).map((input) => this.check(input)),
+ )
.peek(
TraceUtil.promiseify((h) =>
h.get().fold(({ isLeft, value }) => {
- if (isLeft) {
- h.trace.trace(healthCheckMetric.failure);
- h.trace.addTrace(LogLevel.ERROR).trace(`${value}`);
+ if (!isLeft) {
+ h.trace.trace(healthCheckMetric.success);
return;
}
- h.trace.trace(healthCheckMetric.success);
+ h.trace.trace(healthCheckMetric.failure);
+ h.trace.addTrace(LogLevel.ERROR).trace(`${value}`);
}),
),
)
diff --git a/u/trace/itrace.ts b/u/trace/itrace.ts
index 35164b5..c3cb8ad 100644
--- a/u/trace/itrace.ts
+++ b/u/trace/itrace.ts
@@ -16,7 +16,7 @@ export type ITraceableMapper<T, _T, TraceWith, W = ITraceable<T, TraceWith>> = (
export interface ITraceable<T, Trace = BaseTraceWith> {
readonly trace: ITrace<Trace>;
get: Supplier<T>;
- move: <_T>(u: _T) => ITraceable<_T, Trace>;
+ move: <_T>(t: _T) => ITraceable<_T, Trace>;
map: <_T>(mapper: ITraceableMapper<T, _T, Trace>) => ITraceable<_T, Trace>;
bimap: <_T>(
mapper: ITraceableMapper<
@@ -48,7 +48,7 @@ export class TraceableImpl<T, TraceWith> implements ITraceable<T, TraceWith> {
public flatMap<_T>(
mapper: ITraceableMapper<T, ITraceable<_T, TraceWith>, TraceWith>,
): ITraceable<_T, TraceWith> {
- return mapper(this);
+ return mapper(this);
}
public flatMapAsync<_T>(
diff --git a/worker/Dockerfile b/worker/Dockerfile
index 2319a41..8742b44 100644
--- a/worker/Dockerfile
+++ b/worker/Dockerfile
@@ -1,4 +1,4 @@
-# -- <worker.dependencies> --
+# -- <worker_dependencies> --
FROM debian:stable-slim AS worker_dependencies
# Define versions as build arguments to improve caching
@@ -11,9 +11,9 @@ RUN unzip /bw-linux.zip -d / \
RUN curl -L "https://get.docker.com/builds/$(uname -s)/$(uname -m)/docker-latest.tgz" > /docker.tgz
RUN tar -xvzf /docker.tgz
-# -- </worker.dependencies> --
+# -- </worker_dependencies> --
-# -- <ci.worker> --
+# -- <ci_worker> --
FROM oci.liz.coffee/emprespresso/ci_base:release AS worker
RUN apt-get update && apt-get install -yqq git jq
@@ -36,4 +36,4 @@ HEALTHCHECK --interval=10s --retries=3 --start-period=3s \
CMD [ "/usr/bin/laminarc show-jobs" ]
CMD [ "/usr/sbin/laminard" ]
-# -- </ci.worker> --
+# -- </ci_worker> --