add health check to api
This commit is contained in:
@@ -6,8 +6,10 @@ import { fastifyTRPCPlugin } from '@trpc/server/adapters/fastify';
|
|||||||
import Fastify from 'fastify';
|
import Fastify from 'fastify';
|
||||||
import metricsPlugin from 'fastify-metrics';
|
import metricsPlugin from 'fastify-metrics';
|
||||||
|
|
||||||
|
import { db } from '@openpanel/db';
|
||||||
import type { IServiceClient } from '@openpanel/db';
|
import type { IServiceClient } from '@openpanel/db';
|
||||||
import { redisPub } from '@openpanel/redis';
|
import { eventsQueue } from '@openpanel/queue';
|
||||||
|
import { redis, redisPub } from '@openpanel/redis';
|
||||||
import type { AppRouter } from '@openpanel/trpc';
|
import type { AppRouter } from '@openpanel/trpc';
|
||||||
import { appRouter, createContext } from '@openpanel/trpc';
|
import { appRouter, createContext } from '@openpanel/trpc';
|
||||||
|
|
||||||
@@ -79,14 +81,22 @@ const startServer = async () => {
|
|||||||
fastify.get('/', (_request, reply) => {
|
fastify.get('/', (_request, reply) => {
|
||||||
reply.send({ name: 'openpanel sdk api' });
|
reply.send({ name: 'openpanel sdk api' });
|
||||||
});
|
});
|
||||||
// fastify.get('/health-check', async (request, reply) => {
|
fastify.get('/healthcheck', async (request, reply) => {
|
||||||
// try {
|
try {
|
||||||
// await utils.healthCheck()
|
const [redisRes, dbRes, queueRes] = await Promise.all([
|
||||||
// reply.status(200).send()
|
redis.keys('*'),
|
||||||
// } catch (e) {
|
db.project.findFirst(),
|
||||||
// reply.status(500).send()
|
eventsQueue.getCompleted(),
|
||||||
// }
|
]);
|
||||||
// })
|
reply.send({
|
||||||
|
redis: redisRes.length > 0,
|
||||||
|
db: dbRes ? true : false,
|
||||||
|
queue: queueRes.length > 0,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
reply.status(500).send();
|
||||||
|
}
|
||||||
|
});
|
||||||
if (process.env.NODE_ENV === 'production') {
|
if (process.env.NODE_ENV === 'production') {
|
||||||
for (const signal of ['SIGINT', 'SIGTERM']) {
|
for (const signal of ['SIGINT', 'SIGTERM']) {
|
||||||
process.on(signal, (err) => {
|
process.on(signal, (err) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user