(batch: list[tuple])
| 239 | |
| 240 | |
| 241 | async 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 | |
| 261 | async def _write_rollup(batch: list[tuple]) -> None: |
no test coverage detected