feat(api): implement persistent messaging and graceful draining

Add shared sessions, cached message history and transactional idempotency backed by PostgreSQL. Return readiness 503 during draining and finish in-flight requests before closing dependencies.
This commit is contained in:
2026-10-29 11:46:28 +03:00
parent 298204dbe9
commit 24f32c3fbe
35 changed files with 2102 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
import { NestFactory } from '@nestjs/core';
import { NestFastifyApplication } from '@nestjs/platform-fastify';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { apiReference } from '@scalar/nestjs-api-reference';
import { AppModule } from './app.module';
import { Logger } from 'nestjs-pino';
import {
createFastifyAdapter,
DRAIN_DELAY_MS,
exposeRequestIdHeader,
} from './common/http/fastify-adapter';
async function bootstrap() {
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
createFastifyAdapter(DRAIN_DELAY_MS),
{
bufferLogs: true,
},
);
exposeRequestIdHeader(app);
app.useLogger(app.get(Logger));
app.enableShutdownHooks();
const swaggerConfig = new DocumentBuilder()
.setTitle('Messenger API')
.setDescription('Документация API')
.setVersion('1.3.0')
.addBasicAuth({ type: 'http', scheme: 'basic' }, 'basicAuth')
.addBearerAuth(
{ type: 'http', scheme: 'bearer', bearerFormat: 'opaque' },
'bearerAuth',
)
.build();
const document = SwaggerModule.createDocument(app, swaggerConfig);
SwaggerModule.setup('swagger', app, document);
app.use(
'/docs',
apiReference({
content: document,
theme: 'laserwave',
withFastify: true,
}),
);
await app.listen(
Number(process.env.APP_PORT ?? process.env.PORT ?? 8080),
process.env.APP_HOST ?? '0.0.0.0',
);
}
void bootstrap();