summaryrefslogtreecommitdiff
path: root/u/server/activity/health.ts
diff options
context:
space:
mode:
Diffstat (limited to 'u/server/activity/health.ts')
-rw-r--r--u/server/activity/health.ts39
1 files changed, 39 insertions, 0 deletions
diff --git a/u/server/activity/health.ts b/u/server/activity/health.ts
new file mode 100644
index 0000000..bf1f52c
--- /dev/null
+++ b/u/server/activity/health.ts
@@ -0,0 +1,39 @@
+import {
+ Either,
+ getRequiredEnv,
+ getStdout,
+ type ITraceable,
+ LogLevel,
+ type Mapper,
+ TraceUtil,
+} from "@emprespresso/pengueno";
+
+type HealthCheckInput = "healthy?";
+type HealthCheckOutput = "healthy!";
+
+const HealthCheckActivity = <Trace>(
+ check: Mapper<
+ ITraceable<HealthCheckInput, Trace>,
+ Promise<Either<Error, HealthCheckOutput>>
+ >,
+) =>
+(req: ITraceable<Request, Trace>) =>
+ req.bimap(TraceUtil.withFunctionTrace(HealthCheckActivity))
+ .flatMap((r) => r.move(<HealthCheckInput> "healthy?"))
+ .map(check)
+ .map(TraceUtil.promiseify(({ item: health, trace }) => {
+ health.mapBoth((e) => {
+ trace.addTrace(LogLevel.ERROR).trace(`${e}`);
+ return new Response(
+ "oh no, i need to eat more vegetables (。•́︿•̀。)...\n",
+ { status: 500 },
+ );
+ }, (_healthy) => {
+ const msg = `think im healthy!! (✿˘◡˘) ready to do work~`;
+ trace.trace(msg);
+ return new Response(
+ msg + "\n",
+ { status: 200 },
+ );
+ });
+ }));