File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments