Skip to content

Commit 65cd9d6

Browse files
committed
add workaround to ledger
1 parent 12f5ad3 commit 65cd9d6

1 file changed

Lines changed: 26 additions & 8 deletions

File tree

cfa/dataops/catalog.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import pandas as pd
1515
import polars as pl
1616
import tomli
17+
from azure.core.exceptions import ResourceExistsError
1718
from azure.identity import ManagedIdentityCredential
1819
from cfa.cloudops.blob_helpers import (
1920
read_blob_stream,
@@ -544,14 +545,31 @@ def ledger_entry(self, action: str) -> None:
544545
"action": action,
545546
}
546547
log_data = (json.dumps(log_entry) + "\n").encode("utf-8")
547-
write_blob_stream( # TODO: make this a streaming write to a single file (one per day parsed from get_timestamp())
548-
data=log_data,
549-
blob_url=f"{self.ledger_location['prefix']}/{get_date()}.jsonl",
550-
account_name=self.ledger_location["account"],
551-
container_name=self.ledger_location["container"],
552-
append_blob=True,
553-
overwrite=False,
554-
)
548+
ledger_path = f"{self.ledger_location['prefix']}/{get_date()}.jsonl"
549+
try:
550+
write_blob_stream(
551+
data=log_data,
552+
blob_url=ledger_path,
553+
account_name=self.ledger_location["account"],
554+
container_name=self.ledger_location["container"],
555+
append_blob=True,
556+
overwrite=False,
557+
)
558+
except ResourceExistsError as e:
559+
# Azure Append Blobs have a 50,000 block limit; rotate to a new
560+
# timestamped file when the daily file is full.
561+
if "BlockCountExceedsLimit" in str(e):
562+
rotated_path = f"{self.ledger_location['prefix']}/{get_date()}_{get_timestamp()}.jsonl"
563+
write_blob_stream(
564+
data=log_data,
565+
blob_url=rotated_path,
566+
account_name=self.ledger_location["account"],
567+
container_name=self.ledger_location["container"],
568+
append_blob=True,
569+
overwrite=False,
570+
)
571+
else:
572+
raise
555573

556574
def save_dataframe(
557575
self,

0 commit comments

Comments
 (0)