feat: add notification microservices and transactional outbox
هذا الالتزام موجود في:
31
apps/notification-service/src/health.controller.ts
Normal file
31
apps/notification-service/src/health.controller.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
المرجع في مشكلة جديدة
حظر مستخدم