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.
54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
import { z } from 'zod';
|
|
|
|
export const JOB_TYPE = 'attachment.process.v1';
|
|
|
|
/**
|
|
* Mirrors contracts/jobs.schema.json. The broker message carries identifiers
|
|
* and scheduling data only: no bytes, URLs, file names or credentials.
|
|
*/
|
|
export const jobMessageSchema = z.strictObject({
|
|
schema_version: z.literal(1),
|
|
job_id: z.uuid(),
|
|
type: z.literal(JOB_TYPE),
|
|
attachment_id: z.uuid(),
|
|
pipeline_version: z.number().int().min(1),
|
|
attempt: z.number().int().min(1),
|
|
created_at: z.iso.datetime(),
|
|
traceparent: z
|
|
.string()
|
|
.regex(/^00-[0-9a-f]{32}-[0-9a-f]{16}-[0-9a-f]{2}$/u)
|
|
.optional(),
|
|
tracestate: z.string().max(512).optional(),
|
|
});
|
|
|
|
export type JobMessage = z.infer<typeof jobMessageSchema>;
|
|
|
|
export function buildJobMessage(job: {
|
|
job_id: string;
|
|
attachment_id: string;
|
|
pipeline_version: number;
|
|
attempt: number;
|
|
created_at: Date;
|
|
}): JobMessage {
|
|
return {
|
|
schema_version: 1,
|
|
job_id: job.job_id,
|
|
type: JOB_TYPE,
|
|
attachment_id: job.attachment_id,
|
|
pipeline_version: job.pipeline_version,
|
|
attempt: job.attempt,
|
|
created_at: job.created_at.toISOString(),
|
|
};
|
|
}
|
|
|
|
export function parseJobMessage(content: Buffer): JobMessage | undefined {
|
|
let value: unknown;
|
|
try {
|
|
value = JSON.parse(content.toString('utf8'));
|
|
} catch {
|
|
return undefined;
|
|
}
|
|
const parsed = jobMessageSchema.safeParse(value);
|
|
return parsed.success ? parsed.data : undefined;
|
|
}
|