الملفات
back_end_oudelaa/apps/notification-service/src/health.controller.ts
boutmoun123 8147f3b191
فشلت بعض الفحوصات
Deploy To Ghaymah / quality (push) Has been cancelled
Deploy To Ghaymah / deploy (push) Has been cancelled
feat: add notification microservices and transactional outbox
2026-08-05 14:46:12 +03:00

32 أسطر
1.1 KiB
TypeScript

import { Controller, Get, Inject, ServiceUnavailableException } from '@nestjs/common';
import { InjectConnection } from '@nestjs/mongoose';
import { Connection } from 'mongoose';
import { NOTIFICATION_SERVICE_STATE, NotificationServiceState } from './service-state';
@Controller('health')
export class HealthController {
constructor(
@InjectConnection() private readonly connection: Connection,
@Inject(NOTIFICATION_SERVICE_STATE) private readonly state: NotificationServiceState,
) {}
@Get()
@Get('live')
live() {
return { status: this.state.draining ? 'draining' : 'ok', service: 'notification-service' };
}
@Get('ready')
async ready() {
const mongodbReady = this.connection.readyState === 1;
const ready = !this.state.draining && mongodbReady && this.state.rabbitmqReady;
const response = {
status: ready ? 'ready' : 'not-ready',
service: 'notification-service',
checks: { mongodb: mongodbReady, rabbitmq: this.state.rabbitmqReady },
};
if (!ready) throw new ServiceUnavailableException(response);
return response;
}
}