mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-14 01:50:39 +09:00
fix: add periodic flush and graceful shutdown for server-side telemetry
The TelemetryClient only flushed at 50 events, so the server silently lost all queued telemetry on restart. Add startPeriodicFlush/stop methods to TelemetryClient, wire up 60s periodic flush in server initTelemetry, and flush on SIGTERM/SIGINT before exit. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
parent
34044cdfce
commit
f16de6026d
4 changed files with 104 additions and 10 deletions
|
|
@ -18,6 +18,7 @@ export class TelemetryClient {
|
|||
private readonly version: string;
|
||||
private readonly sessionId: string;
|
||||
private state: TelemetryState | null = null;
|
||||
private flushInterval: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
constructor(config: TelemetryConfig, stateFactory: () => TelemetryState, version: string) {
|
||||
this.config = config;
|
||||
|
|
@ -68,6 +69,24 @@ export class TelemetryClient {
|
|||
}
|
||||
}
|
||||
|
||||
startPeriodicFlush(intervalMs: number = 60_000): void {
|
||||
if (this.flushInterval) return;
|
||||
this.flushInterval = setInterval(() => {
|
||||
void this.flush();
|
||||
}, intervalMs);
|
||||
// Allow the process to exit even if the interval is still active
|
||||
if (typeof this.flushInterval === "object" && "unref" in this.flushInterval) {
|
||||
this.flushInterval.unref();
|
||||
}
|
||||
}
|
||||
|
||||
stop(): void {
|
||||
if (this.flushInterval) {
|
||||
clearInterval(this.flushInterval);
|
||||
this.flushInterval = null;
|
||||
}
|
||||
}
|
||||
|
||||
hashPrivateRef(value: string): string {
|
||||
const state = this.getState();
|
||||
return createHash("sha256")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue