Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/indexer-cache-validator/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { cache, logger, shutdownOperation, timeOperation } from "@intmax2-function/shared";
import { name } from "../package.json";
import { INTERVAL_MS } from "./constants";
import { startHealthCheckServer } from "./lib/healthCheck";
import { performJob } from "./service/job.service";

async function executeJob() {
Expand Down Expand Up @@ -29,6 +30,14 @@ async function scheduleNextExecution() {
}

async function main() {
try {
await startHealthCheckServer();
logger.info("Health check server started successfully");
} catch (error) {
logger.error("Failed to start health check server:", error);
throw error;
}

logger.info(`Starting ${name} adaptive interval job (target interval: ${INTERVAL_MS / 1000}s)`);

scheduleNextExecution();
Expand Down
29 changes: 29 additions & 0 deletions packages/indexer-cache-validator/src/lib/healthCheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import http from "node:http";
import { config, logger } from "@intmax2-function/shared";
import { name } from "../../package.json";

const server = http.createServer(async (req, res) => {
if (req.url === "/v1/health" && req.method === "GET") {
res.writeHead(200, { "Content-Type": "application/json" });
res.end(
JSON.stringify({
status: "healthy",
service: name,
timestamp: new Date().toISOString(),
}),
);
return;
}

res.writeHead(404);
res.end();
});

export const startHealthCheckServer = async () => {
return new Promise((resolve) => {
server.listen(config.PORT, () => {
logger.info(`Health check server is running on port ${config.PORT}`);
resolve(true);
});
});
};