mirror of
https://github.com/getwax/bls-wallet.git
synced 2026-01-08 23:28:21 -05:00
Add /health to aggregator
This commit is contained in:
@@ -88,4 +88,5 @@ type AppEvent =
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
export default AppEvent;
|
||||
|
||||
@@ -2,7 +2,6 @@ import { Router } from "../../deps.ts";
|
||||
import failRequest from "./helpers/failRequest.ts";
|
||||
import BundleHandler from "./helpers/BundleHandler.ts";
|
||||
import nil from "../helpers/nil.ts";
|
||||
|
||||
import BundleService from "./BundleService.ts";
|
||||
|
||||
export default function BundleRouter(bundleService: BundleService) {
|
||||
|
||||
16
aggregator/src/app/HealthRouter.ts
Normal file
16
aggregator/src/app/HealthRouter.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Router } from "../../deps.ts";
|
||||
import HealthService from "./HealthService.ts";
|
||||
|
||||
export default function HealthRouter(healthService: HealthService) {
|
||||
const router = new Router({ prefix: "/" });
|
||||
|
||||
router.get(
|
||||
"health",
|
||||
async (ctx) => {
|
||||
const healthResults = await healthService.getHealth();
|
||||
console.log(`Status: ${healthResults.status}\n`);
|
||||
ctx.response.status = healthResults.status == 'healthy' ? 200 : 503;
|
||||
ctx.response.body = { status: healthResults.status };
|
||||
});
|
||||
return router;
|
||||
}
|
||||
11
aggregator/src/app/HealthService.ts
Normal file
11
aggregator/src/app/HealthService.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
export type ResourceHealth = 'healthy' | 'unhealthy';
|
||||
|
||||
type HealthCheckResult = {
|
||||
status: ResourceHealth,
|
||||
};
|
||||
|
||||
export default class HealthService {
|
||||
getHealth(): Promise<HealthCheckResult> {
|
||||
return Promise.resolve({ status: 'healthy' });
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,8 @@ import AppEvent from "./AppEvent.ts";
|
||||
import BundleTable from "./BundleTable.ts";
|
||||
import AggregationStrategy from "./AggregationStrategy.ts";
|
||||
import AggregationStrategyRouter from "./AggregationStrategyRouter.ts";
|
||||
import HealthService from "./HealthService.ts";
|
||||
import HealthRouter from "./HealthRouter.ts";
|
||||
|
||||
export default async function app(emit: (evt: AppEvent) => void) {
|
||||
const { addresses } = await getNetworkConfig();
|
||||
@@ -64,10 +66,13 @@ export default async function app(emit: (evt: AppEvent) => void) {
|
||||
bundleTable,
|
||||
);
|
||||
|
||||
const healthService = new HealthService();
|
||||
|
||||
const routers = [
|
||||
BundleRouter(bundleService),
|
||||
AdminRouter(adminService),
|
||||
AggregationStrategyRouter(aggregationStrategy),
|
||||
HealthRouter(healthService),
|
||||
];
|
||||
|
||||
const app = new Application();
|
||||
|
||||
10
aggregator/test/HealthService.test.ts
Normal file
10
aggregator/test/HealthService.test.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { assertEquals } from "./deps.ts";
|
||||
|
||||
import Fixture from "./helpers/Fixture.ts";
|
||||
|
||||
Fixture.test("HealthService returns healthy", async (fx) => {
|
||||
const healthCheckService = fx.createHealthCheckService()
|
||||
const healthStatus = await healthCheckService.getHealth();
|
||||
const expected = {"status":"healthy"};
|
||||
assertEquals(JSON.stringify(healthStatus), JSON.stringify(expected));
|
||||
});
|
||||
@@ -25,6 +25,7 @@ import BundleTable, { BundleRow } from "../../src/app/BundleTable.ts";
|
||||
import AggregationStrategy, {
|
||||
AggregationStrategyConfig,
|
||||
} from "../../src/app/AggregationStrategy.ts";
|
||||
import HealthService from "../../src/app/HealthService.ts";
|
||||
|
||||
// deno-lint-ignore no-explicit-any
|
||||
type ExplicitAny = any;
|
||||
@@ -292,6 +293,12 @@ export default class Fixture {
|
||||
|
||||
return wallets;
|
||||
}
|
||||
|
||||
createHealthCheckService() {
|
||||
const healthCheckService = new HealthService();
|
||||
|
||||
return healthCheckService;
|
||||
}
|
||||
|
||||
async cleanup() {
|
||||
for (const job of this.cleanupJobs) {
|
||||
|
||||
Reference in New Issue
Block a user