MCPcopy Create free account
hub / github.com/Roy3838/Observer / _write_archive

Function _write_archive

api/usage_log.py:241–258  ·  view source on GitHub ↗
(batch: list[tuple])

Source from the content-addressed store, hash-verified

239
240
241async def _write_archive(batch: list[tuple]) -> None:
242 global _seq
243 _seq += 1
244 # Keyed by flush time, not by the events' own timestamps: a batch spans up
245 # to BATCH_INTERVAL and can straddle midnight, so an object dated today may
246 # hold up to a minute of yesterday. Every row carries its own `ts`, so a
247 # reader filtering on that is exact; a reader filtering on the key prefix
248 # should widen the range by a day at each end.
249 now = datetime.now(timezone.utc)
250 body = await asyncio.to_thread(
251 lambda: gzip.compress(_encode_batch(batch), compresslevel=6)
252 )
253 key = r2_store.usage_key(
254 now.strftime("%Y-%m-%d"), HOST_ID, now.strftime("%H%M%S"), RUN_TOKEN, _seq
255 )
256 await r2_store.put_bytes(
257 key, body, content_type="application/x-ndjson", content_encoding="gzip"
258 )
259
260
261async def _write_rollup(batch: list[tuple]) -> None:

Callers 1

_flushFunction · 0.85

Calls 1

_encode_batchFunction · 0.85

Tested by

no test coverage detected