File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1414import pandas as pd
1515import polars as pl
1616import tomli
17+ from azure .core .exceptions import ResourceExistsError
1718from azure .identity import ManagedIdentityCredential
1819from 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 ,
You can’t perform that action at this time.
0 commit comments