MCPcopy Create free account
hub / github.com/CommonstackAI/UncommonRoute / flush

Function flush

uncommon_route/telemetry.py:247–269  ·  view source on GitHub ↗

Send buffered records to the collection endpoint. Returns count sent.

()

Source from the content-addressed store, hash-verified

245
246
247def flush() -> int:
248 """Send buffered records to the collection endpoint. Returns count sent."""
249 buf = _buffer_path()
250 if not buf.exists():
251 return 0
252 try:
253 records_text = buf.read_text().strip()
254 if not records_text:
255 return 0
256 lines = records_text.splitlines()
257 success = _send_batch(lines)
258 if success:
259 # Write to sent log (audit trail for successfully sent records)
260 sent = _sent_log_path()
261 with open(sent, "a", encoding="utf-8") as f:
262 for line in lines:
263 f.write(line + "\n")
264 # Clear buffer
265 buf.unlink(missing_ok=True)
266 return len(lines)
267 except Exception as e:
268 logger.debug("Telemetry flush failed: %s", e)
269 return 0
270
271
272def _send_batch(lines: list[str]) -> bool:

Callers 1

_cmd_telemetryFunction · 0.90

Calls 4

_buffer_pathFunction · 0.85
_send_batchFunction · 0.85
_sent_log_pathFunction · 0.85
openFunction · 0.85

Tested by

no test coverage detected