diff options
author | Elizabeth Hunt <me@liz.coffee> | 2025-06-29 17:31:30 -0700 |
---|---|---|
committer | Elizabeth Hunt <me@liz.coffee> | 2025-06-29 17:31:30 -0700 |
commit | 58be1809c46cbe517a18d86d0af52179dcc5cbf6 (patch) | |
tree | 9ccc678b3fd48c1a52fe501600dd2c2051740a55 /u/server/activity/health.ts | |
parent | d4791f3d357634daf506fb8f91cc5332a794c421 (diff) | |
download | ci-58be1809c46cbe517a18d86d0af52179dcc5cbf6.tar.gz ci-58be1809c46cbe517a18d86d0af52179dcc5cbf6.zip |
Move to nodejs and also lots of significant refactoring that should've been broken up but idgaf
Diffstat (limited to 'u/server/activity/health.ts')
-rw-r--r-- | u/server/activity/health.ts | 40 |
1 files changed, 11 insertions, 29 deletions
diff --git a/u/server/activity/health.ts b/u/server/activity/health.ts index b3ae559..9396490 100644 --- a/u/server/activity/health.ts +++ b/u/server/activity/health.ts @@ -23,7 +23,7 @@ export interface IHealthCheckActivity { checkHealth: IActivity; } -const healthCheckMetric: IMetric = Metric.fromName('Health'); +const healthCheckMetric = Metric.fromName('Health').asResult(); export interface HealthChecker extends Mapper<ITraceable<HealthCheckInput, ServerTrace>, Promise<IEither<Error, HealthCheckOutput>>> {} export class HealthCheckActivityImpl implements IHealthCheckActivity { @@ -31,36 +31,18 @@ export class HealthCheckActivityImpl implements IHealthCheckActivity { public checkHealth(req: ITraceable<PenguenoRequest, ServerTrace>) { return req - .bimap(TraceUtil.withFunctionTrace(this.checkHealth)) - .bimap(TraceUtil.withMetricTrace(healthCheckMetric)) + .flatMap(TraceUtil.withFunctionTrace(this.checkHealth)) + .flatMap(TraceUtil.withMetricTrace(healthCheckMetric)) .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.success); - return; - } - h.trace.trace(healthCheckMetric.failure); - h.trace.addTrace(LogLevel.ERROR).trace(value); - }), - ), - ) + .peek(TraceUtil.promiseify(TraceUtil.traceResultingEither(healthCheckMetric))) .map( - TraceUtil.promiseify((h) => - h - .get() - .mapBoth( - () => 'oh no, i need to eat more vegetables (。•́︿•̀。)...', - () => 'think im healthy!! (✿˘◡˘) ready to do work~', - ) - .fold( - ({ isLeft, value: message }) => - new JsonResponse(req, message, { - status: isLeft ? 500 : 200, - }), - ), - ), + TraceUtil.promiseify((h) => { + const { status, message } = h.get().fold( + () => ({ status: 500, message: 'err' }), + () => ({ status: 200, message: 'ok' }), + ); + return new JsonResponse(req, message, { status }); + }), ) .get(); } |