Skip to content

Commit d027f4e

Browse files
telemetry-logger.js erstellen
1 parent 37e1d73 commit d027f4e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

api/ws/telemetry-logger.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import fs from "fs";
2+
import path from "path";
3+
4+
const DATA_DIR = process.env.DATA_DIR || "./data";
5+
const TELE_DIR = path.join(DATA_DIR, "telemetry");
6+
fs.mkdirSync(TELE_DIR, { recursive: true });
7+
8+
// in-memory switch
9+
const active = new Set();
10+
11+
export function startTelemetryLoggingForMission(missionId) {
12+
active.add(missionId);
13+
}
14+
15+
export function stopTelemetryLoggingForMission(missionId) {
16+
active.delete(missionId);
17+
}
18+
19+
export function appendTelemetry(missionId, telemetryObj) {
20+
if (!active.has(missionId)) return;
21+
22+
const fp = path.join(TELE_DIR, `${missionId}.jsonl`);
23+
const line = JSON.stringify({ ts: Date.now(), ...telemetryObj }) + "\n";
24+
fs.appendFileSync(fp, line, "utf-8");
25+
}

0 commit comments

Comments
 (0)