-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathingest-bun.controller.ts
More file actions
42 lines (34 loc) · 1.08 KB
/
ingest-bun.controller.ts
File metadata and controls
42 lines (34 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { Controller, Post, Body, Get } from '@nestjs/common';
import { IngestBunService } from './ingest-bun.service';
export interface IngestResponse {
id: string;
t_ms: number;
}
export interface HealthResponse {
status: string;
timestamp: string;
runtime: string;
}
@Controller()
export class IngestBunController {
constructor(private readonly ingestService: IngestBunService) {}
@Post('ingest')
async ingest(@Body() payload: Record<string, any>): Promise<IngestResponse> {
const startTime = process.hrtime.bigint();
const id = await this.ingestService.process(payload);
const endTime = process.hrtime.bigint();
const elapsedMs = Number(endTime - startTime) / 1000000; // Convert nanoseconds to milliseconds
return {
id,
t_ms: Math.round(elapsedMs * 100) / 100 // Round to 2 decimal places
};
}
@Get('health')
getHealth(): HealthResponse {
return {
status: 'ok',
timestamp: new Date().toISOString(),
runtime: typeof Bun !== 'undefined' ? `Bun ${Bun.version}` : `Node.js ${process.version}`
};
}
}