forked from mtusi2026/mtusi2026lab6
Перенесено дерево lab5 целиком: NestJS-приложение (API + worker,
RabbitMQ, outbox, S3), Dockerfile, compose.yaml, infra/{haproxy,minio,
rabbitmq}, стендовые скрипты, scripts/lab4, scripts/lab5,
evidence/lab4, evidence/lab5 и contracts/extensions.openapi.json.
Задание lab6 оставлено своим: README, REPORT, COURSE, lab.json,
contracts/{openapi,infrastructure,jobs.schema,attachment-states,
examples,observability}, tests, compose.example.yaml, infra/otel,
.github/pull_request_template.md.
Адаптации при переносе:
- docker-проект mtusi-lab5 -> mtusi-lab6 и тег образа
mtusi-messenger:lab6 (compose.yaml, scripts/stop-one.sh, .env.example,
infra/README.md), чтобы тома и контейнеры не пересекались с lab5;
- Makefile: цели lab5 сохранены целиком (skeleton lab6 не отличается
от skeleton lab5);
- .env.example: переменные приложения и стенда lab5 + блок lab6
(OTEL_*) из skeleton.
15 lines
666 B
TypeScript
15 lines
666 B
TypeScript
import { randomUUID } from 'node:crypto';
|
|
import { hostname } from 'node:os';
|
|
import type { ConfigService } from '@nestjs/config';
|
|
import type { AppConfig } from './app-config.schema.js';
|
|
|
|
// A replica must be identifiable from the outside. Inside Docker the hostname is
|
|
// the short container ID, so X-Instance-Id can be mapped back to exactly one
|
|
// container; INSTANCE_ID exists for platforms where that mapping is not useful.
|
|
export function resolveInstanceId(config: ConfigService<AppConfig>): string {
|
|
const configured = config.get('INSTANCE_ID');
|
|
if (configured) return configured;
|
|
const host = hostname();
|
|
return host.length > 0 ? host : randomUUID();
|
|
}
|